httplib模塊是一個底層基礎(chǔ)模塊,實(shí)現(xiàn)的功能比較少,正常情況下比較少用到.推薦用urllib, urllib2, httplib2.
HTTPConnection 對象
class httplib.HTTPConnection(host[, port[, strict[, timeout[, source_address]]]])
創(chuàng)建HTTPConnection對象
HTTPConnection.request(method, url[, body[, headers]])
發(fā)送請求
HTTPConnection.getresponse()
獲得響應(yīng)
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
獲得頭內(nèi)容
HTTPResponse.version
獲得頭http版本
HTTPResponse.status
獲得返回狀態(tài)碼
HTTPResponse.reason
獲得返回說明
實(shí)例
conn = httplib.HTTPConnection("m.survivalescaperooms.com")
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
輸出:
新聞熱點(diǎn)
疑難解答
圖片精選