httplib2Python HTTP 库

联合创作 · 2023-09-29 13:10

httplib2是一个使用python写的支持的非常全面的http特性的库。需要Python2.3或更高版本的运行环境,0.5.0版及其以后包含了对Python3的支持。

简单的例子:

 

import httplib2
h = httplib2.Http(".cache")
resp, content = h.request("http://example.org/", "GET")

 

认证实例:

 

 

import httplib2
h = httplib2.Http(".cache")
h.add_credentials('name', 'password')
resp, content = h.request("https://example.org/chap/2", 
    "PUT", body="This is text", 
    headers={'content-type':'text/plain'} )

 

缓存控制:

 

 

import httplib2
h = httplib2.Http(".cache")
resp, content = h.request("http://bitworking.org/")
 ...
resp, content = h.request("http://bitworking.org/", 
    headers={'cache-control':'no-cache'})

 

浏览 7
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报