使用python请求发送post请求:Content-Type = multipart / form-data;

时间:2017-01-16 11:20:03

标签: python http python-requests

请求有效负载:

------WebKitFormBoundarygwvtBWIEYsiYIdsp

Content-Disposition: form-data; name="sourceZoneId"

10

------WebKitFormBoundarygwvtBWIEYsiYIdsp

Content-Disposition: form-data; name="targetZoneId"

11

------WebKitFormBoundarygwvtBWIEYsiYIdsp

Content-Disposition: form-data; name="description"

test upload



------WebKitFormBoundarygwvtBWIEYsiYIdsp

Content-Disposition: form-data; name="files[0]"; filename="github.txt"
Content-Type: text/plain



------WebKitFormBoundarygwvtBWIEYsiYIdsp--

我发送了这样的POST请求:

headers = {'Content-Type':'multipart/form-data; boundary=----WebKitFormBoundarygwvtBWIEYsiYIdsp','Accept':'*/*','x-auth-token':token}

files = {'sourceZoneId':'10',
               'targetZoneId':'11',
               'description':'test upload',
               'file[0]':('github.txt',open('E:\chenyao\github.txt','rb'),'text/plain')}

requests.post(url,header = headers, files = files)

但返回HTTP 400错误请求。谁知道为什么?谢谢!

0 个答案:

没有答案