根据http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3客户端必须等待 100(继续)状态,然后才能进行 POST(在需要此 header 的 HTTP 1.1 服务器上)。
我无法理解 Python 是如何做到这一点的。例如:
conn = httplib.HTTPConnection(url)
conn.putrequest('POST', page)
conn.putheader(...)
conn.putheader('Expect', '100-continue')
conn.endheaders()
现在,我没有看到其他选项然后发送数据:
conn.send(data)
在这种情况下,我在请求响应时出错:
error: [Errno 10053] An established connection was aborted by the software in your host machine
如何请求状态 100,以便发送数据?
最佳答案
我不认为 httplib
支持这个(非常好);参见 this requests ticket 中的讨论, 具体来说
and can close the socket early in a way that breaks httplib
该评论的作者 Augie Fackler (durin42) 也提到了他自己的 httpplus
library .
快速浏览 source code表明 它 确实可以正确处理 Expect: 100-Continue
的 promise :
# handle 100-continue response
hdrs, body = self.raw_response.split(self._end_headers, 1)
http_ver, status = hdrs.split(' ', 1)
if status.startswith('100'):
self.raw_response = body
self.continued = True
logger.debug('continue seen, setting body to %r', body)
return
关于python - HTTP 1.1 期望 header 握手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15569589/