2013-03-22 25 views
1

根据http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3客户端在POST(在需要此头的HTTP 1.1服务器上)之前必须等待100(继续)状态。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,以便我可以发送数据?

+1

我不认为'httplib'支持这一(非常好);请参阅[this' requests' ticket](https://github.com/kennethreitz/requests/issues/713)中的讨论(特别是*,并且可以以打破httplib *备注的方式尽早关闭套接字)。 – 2013-03-22 11:54:27

+0

如果您读取异常消息,您将看到连接已中止。网络好吗?你拉了网线吗?有DPI的防火墙可以阻止POST POST请求吗? – 2013-03-22 11:56:51

+0

我想我们不能期望在这种情况下有意义的例外。我对我的网络没有任何问题,例如Java中的相同代码按预期工作。 – theta 2013-03-22 11:59:50

回答

2

我不认为httplib支持这(很好);看到讨论this requests ticket,具体

,并可以在休息的方式httplib的

该评论的作者早关闭套接字,奥吉法克勒(durin42)也提到了自己的httpplus library

source code显示快速浏览承诺不正确处理Expect: 100-Continue

# 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 
+0

谢谢你。如果没有你的评论,我永远不会找到这个图书馆。使用httpplus而不是urllib2解决了一个类似的问题,我需要支持100个继续。 – 2014-07-16 15:46:57