發送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