POST
只要Content-Length
标头被发送并设置为 ,发送带有空正文的请求是完全合法的0
。请求通常计算Content-Length
标头的值。您观察到的行为可能是由于问题223 - Content-Length is missing。尽管该错误尚未关闭,但问题似乎已解决:
C:\>python
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.__version__
'0.11.1'
>>> r = requests.post('http://httpbin.org/post?key1=valueA&key2=valueB')
>>> print r.content
{
"origin": "77.255.249.138",
"files": {},
"form": {},
"url": "http://httpbin.org/post?key1=valueA&key2=valueB",
"args": {
"key2": "valueB",
"key1": "valueA"
},
"headers": {
"Content-Length": "0",
"Accept-Encoding": "identity, deflate, compress, gzip",
"Connection": "keep-alive",
"Accept": "*/*",
"User-Agent": "python-requests/0.11.1",
"Host": "httpbin.org",
"Content-Type": ""
},
"json": null,
"data": ""
}