HTTP 1.1 Expect标头握手 [英] HTTP 1.1 Expect header handshake

查看:105
本文介绍了HTTP 1.1 Expect标头握手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 http://www.w3.org/Protocols /rfc2616/rfc2616-sec8.html#sec8.2.3 客户端必须等待100(继续)状态,才能进行POST(在需要此标头的HTTP 1.1服务器上)。

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).

我无法理解Python如何做到这一点。例如:

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

我如何要求提供状态100,以便我可以发送数据?

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

推荐答案

我认为 httplib 支持这个(非常好);请参阅此请求票据中的讨论,具体为

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


并且可以以破坏httplib的方式提前关闭套接字

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

该评论,Augie Fackler(durin42)也提到他自己的 httpplus 图书馆

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

快速浏览源代码显示 it 确实处理的承诺 Expect:100-Continue 正确:

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

这篇关于HTTP 1.1 Expect标头握手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆