当前位置: 动力学知识库 > 问答 > 编程问答 >

python - HTTP 1.1 Expect header handshake

问题描述:

According http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3 client has to wait for 100 (Continue) status, before making POST (on HTTP 1.1 server that requires this header).

I can't understand how can Python do this. For example:

conn = httplib.HTTPConnection(url)

conn.putrequest('POST', page)

conn.putheader(...)

conn.putheader('Expect', '100-continue')

conn.endheaders()

Now, I don't see other options then send the data:

conn.send(data)

in which case I get error, when asking for response:

error: [Errno 10053] An established connection was aborted by the software in your host machine

How can I ask for status 100, so that I can send the data?

网友答案:

I don't think httplib supports this (very well); see the discussion in this requests ticket, specifically

and can close the socket early in a way that breaks httplib

The author of that comment, Augie Fackler (durin42) also mentions his own httpplus library.

A quick glance at the source code shows promise that it does handle Expect: 100-Continue correctly:

# 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
分享给朋友:
您可能感兴趣的文章:
随机阅读: