python upload string with https post
This question already has an answer here:
When using the files
parameter, requests
creates the headers and body required to post files.
If you don't want your request formated like that you can use the data
parameter.
url = 'http://httpbin.org/anything'
headers = {'content-type': 'application/octet-stream'}
files = {'file': 'ID,Namen1,test'}
r = requests.post(url, data=files, headers=headers, auth=('user', 'password'))
print(r.request.body)
file=ID%2CName%0A1%2Ctest
Note that when passing a dictionary to data
it gets url-encoded. If you want to submit your data without any encoding you can use a string.
url = 'http://httpbin.org/anything'
headers = {'content-type': 'application/octet-stream'}
files = 'ID,Namen1,test'
r = requests.post(url, data=files, headers=headers, auth=('user', 'password'))
print(r.request.body)
ID,Name
1,test
链接地址: http://www.djcxy.com/p/41322.html