足球游戏_中国足彩网¥体育资讯$

python httplib模块使用实例
来源:易贤网 阅读:669 次 日期:2016-06-14 11:12:11
温馨提示:易贤网小编为您整理了“python httplib模块使用实例”,方便广大网友查阅!

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

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

中国足彩网信息请查看脚本栏目
易贤网手机网站地址:python httplib模块使用实例
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 足球游戏_中国足彩网¥体育资讯$ 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标