V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
sparkssssssss
V2EX  ›  Python

请教个 multipart/form-data 类型的 post 请求!

  •  
  •   sparkssssssss · Feb 7, 2021 · 1404 views
    This topic created in 1904 days ago, the information mentioned may be changed or developed.
    公司 app 每天要填,我就想着抓个包,跑个脚本就拉倒了,抓出来看了下 post data 是如下类型的
    ------WebKitFormBoundaryiUAjmCJTuZqIbnNA
    Content-Disposition: form-data; name="datasource"

    $ECOLOGY_SYS_LOCAL_POOLNAME
    ------WebKitFormBoundaryiUAjmCJTuZqIbnNA
    Content-Disposition: form-data; name="formtype"

    1
    ------WebKitFormBoundaryiUAjmCJTuZqIbnNA
    ......

    先用 post 工具发送了个,没问题,看了下 post 参数如下
    https://sm.ms/image/WRO67r9ni5cyoKY

    然后就用 request.post(url,headers=xxx,data=xxx),请求参数同上,但是就不成功,发现 postbody 如下
    https://sm.ms/image/N8F2dJR9efMlZAi


    请教下,这种数据是怎么构造 payload 啊,搜了下,没太明白
    jifengg
        1
    jifengg  
       Feb 7, 2021   ❤️ 1
    form-data 里的分隔符是 \r\n,是不是你只用了\n ?
    sparkssssssss
        3
    sparkssssssss  
    OP
       Feb 7, 2021
    @jifengg 非常感谢,是这个问题,我 replace("\n","\r\n"),可以正常提交了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   844 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 21:22 · PVG 05:22 · LAX 14:22 · JFK 17:22
    ♥ Do have faith in what you're doing.