requests.post(url,headers={'content-type':'application/x-www-form-urlencoded'},data='f=10')
requests.post(url,headers={'content-type':'application/x-www-form-urlencoded'},data={'f':10})
requests.post(url,headers={'content-type':'application/json'},data=json.dumps({'f':10}))
requests.post(url,headers={'content-type':'application/json'},json={'f':10})
requests.post(url,headers={'content-type':'text/xml'},data='<xml......>'.encode("utf-8"))
举个例子:
Request Headers
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryzf3ou2ZJHNJq9V0N
------------------------------------------------------------
FormData
file: (binary)
else1: xxx1
else2: xxx2
------------------------------------------------------------
FormData view source
------WebKitFormBoundaryzf3ou2ZJHNJq9V0N
Content-Disposition: form-data; name="file"; filename="test.jpg"
Content-Type: image/jpeg
------WebKitFormBoundaryzf3ou2ZJHNJq9V0N
Content-Disposition: form-data; name="else1"
xxx1
------WebKitFormBoundaryzf3ou2ZJHNJq9V0N
Content-Disposition: form-data; name="else2"
xxx2
------WebKitFormBoundaryzf3ou2ZJHNJq9V0N--
可以整理如下方式提交
files = {
"file":("test.jpg", open(r"D:\test\test.jpg",'rb')),
"else1": (None,"xxx1"),
"else2": (None,"xxx2")
}
r = requests.post(url,files=files)