本文介绍了如何通过 urllib2 发送 HTTP/1.0 请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
似乎urllib2默认发送HTTP/1.1请求?
Seems that urllib2 sends HTTP/1.1 request by default?
推荐答案
urllib2 在幕后使用 httplib 进行连接.您可以将其更改为 http 1.0,如下所示.我已经包含了我的 apache 服务器访问日志以显示 http 连接如何更改为 1.0
urllib2 uses httplib under the hood to make the connection. You can change it to http 1.0 as shown below. I've included my apache servers access log to show how the http connection have change to 1.0
代码
import urllib2, httplib
httplib.HTTPConnection._http_vsn = 10
httplib.HTTPConnection._http_vsn_str = 'HTTP/1.0'
print urllib2.urlopen('http://localhost/').read()
access.log
127.0.0.1 - - [01/Dec/2012:09:10:27 +0300] "GET / HTTP/1.1" 200 454 "-" "Python-urllib/2.7"
127.0.0.1 - - [01/Dec/2012:09:16:32 +0300] "GET / HTTP/1.0" 200 454 "-" "Python-urllib/2.7"
这篇关于如何通过 urllib2 发送 HTTP/1.0 请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!