python - HTTP 1.1 期望 header 握手

标签 python http

根据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/

相关文章:

python - 使用 Python 提交高级 eBay 搜索

java - 为什么我的代码返回 403 禁止访问

python - Django - 如何将异步任务队列与 celery 和 redis 一起使用

python - 单词出现的次数

javascript - 如何在 NodeJS 中测量 http.ClientRequest 响应时间?

python - 使用自定义状态代码在 Python Bottle 中发送字典作为响应

linux - hgweb 服务器中止 : HTTP Error 404: Condition Intercepted

注入(inject) URL 的 Javascript

java - tabula-py Java版本错误

python - Cython 编译器错误