发送http请求时,以form-data的格式作为requests的参数


使用requests的requests_toolbelt模块 ,需要自行安装。

http://testingpai.com/article/1595507314591

from requests_toolbelt import MultipartEncoder
import requests

m = MultipartEncoder(
fields={'field0': 'value',
'field1': 'value',
'field2': ('文件名称', open('文件地址/file.py', 'rb'), 'text/plain')}
)

r = requests.post('http://httpbin.org/post',
data=m,
headers={'Content-Type': m.content_type})

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM