httplib模块是一个底层基础模块,实现的功能比较少,正常情况下比较少用到.推荐用urllib, urllib2, httplib2.
HTTPConnection 对象
class httplib.HTTPConnection(host[, port[, strict[, timeout[, source_address]]]])
创建HTTPConnection对象
HTTPConnection.request(method, url[, body[, headers]])
发送请求
HTTPConnection.getresponse()
获得响应
HTTPResponse对象
HTTPResponse.read([amt])
Reads and returns the response body, or up to the next amt bytes.
HTTPResponse.getheader(name[, default])
获得指定头信息
HTTPResponse.getheaders()
获得(header, value)元组的列表
HTTPResponse.fileno()
获得底层socket文件描述符
HTTPResponse.msg
获得头内容
HTTPResponse.version
获得头http版本
HTTPResponse.status
获得返回状态码
HTTPResponse.reason
获得返回说明
实例
复制代码 代码如下:
#!/usr/bin/python
import httplib
conn = httplib.HTTPConnection("www.jb51.net")
conn.request("GET", "/")
r1 = conn.getresponse()
print r1.status, r1.reason
print '-' * 40
headers = r1.getheaders()
for h in headers:
print h
print '-' * 40
print r1.msg
输出:
复制代码 代码如下:
200 OK
----------------------------------------
('content-length', '106883')
('accept-ranges', 'bytes')
('vary', 'Accept-Encoding, Accept-Encoding')
('keep-alive', 'timeout=20')
('server', 'ngx_openresty')
('last-modified', 'Fri, 10 Apr 2015 09:30:10 GMT')
('connection', 'keep-alive')
('etag', '"55279822-1a183"')
('date', 'Fri, 10 Apr 2015 09:48:15 GMT')
('content-type', 'text/html; charset=utf-8')
----------------------------------------
Server: ngx_openresty
Date: Fri, 10 Apr 2015 09:48:15 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 106883
Connection: keep-alive
Keep-Alive: timeout=20
Vary: Accept-Encoding
Last-Modified: Fri, 10 Apr 2015 09:30:10 GMT
Vary: Accept-Encoding
ETag: "55279822-1a183"
Accept-Ranges: bytes
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 《原神》「星路拾忆」网页活动壁纸展示
- 群星.2024-祝你幸福!电影原声带【阿里巴巴】【FLAC分轨】
- 于台烟.2004-执着【乾坤唱片】【WAV+CUE】
- 黄品源.2004-感谢·情人(引进版)【滚石】【WAV+CUE】
- 《最终幻想16》评测:游、戏两难全的系列转折
- 《纸嫁衣》五部打包¥104,《鬼泣5》仅需¥44
- 《崩坏:星穹铁道》造物大赛卷出新高度
- 《王菲 菲常传奇 2CD》[WAV+CUE][950MB]
- 《王菲 空灵独味唱腔 非常传奇 紫水晶2CD》[WAV+CUE][860MB]
- 《车载专业测试王1号 极品音质》[WAV/分轨][980MB]
- 炉石传说的国服回归送什么奖励 炉石传说9.25回归最新消息介绍
- 云顶之弈最强阵容汇总2024 云顶之弈最强阵容搭配最新版本
- S14lol全球总决赛在哪观看 lol全球总决赛观赛直播地址汇总
- 黄思婷2011-感谢天[豪记唱片][WAV+CUE]
- 孙淑媚2013-太阳[台湾首版][WAV+CUE]