httplib2Python HTTP 库
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'})
评论