您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

使用Python 2中的urllib2发出HTTP HEAD请求

使用Python 2中的urllib2发出HTTP HEAD请求

这很好用:

import urllib2
request = urllib2.Request('http://localhost:8080')
request.get_method = lambda : 'HEAD'

response = urllib2.urlopen(request)
print response.info()

经过python入侵的快速而肮脏的HTTPd的测试:

Server: BaseHTTP/0.3 Python/2.6.6
Date: Sun, 12 Dec 2010 11:52:33 GMT
Content-type: text/html
X-REQUEST_METHOD: HEAD

添加一个自定义标头字段X-REQUEST_METHOD以显示它的工作:)

这是HTTPd日志:

Sun Dec 12 12:52:28 2010 Server Starts - localhost:8080
localhost.localdomain - - [12/Dec/2010 12:52:33] "HEAD / HTTP/1.1" 200 -

编辑:还有httplib2

import httplib2
h = httplib2.Http()
resp = h.request("http://www.google.com", 'HEAD')
python 2022/1/1 18:43:56 有298人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶