雖然說httplib跟request比起來沦辙,用的人已經(jīng)不多了夫植,但是會(huì)寫一個(gè)簡單的demo還是有必要的,下面就是我初次下手寫的demo油讯,里面有一些錯(cuò)誤详民,你能看出來嗎?
coding=utf-8
import httplib
url = "http://www.baidu.com/"
host = "www.baidu.com"
location = "/"-------------------location在這里不是必須的
body = ''
method = "get"-----------------應(yīng)該用大寫的‘GET’
headers = {}
conn = httplib.HTTPConnection(host)
conn.request(method, url, body, headers)
res = conn.getresponse()
print res.status()--------------------應(yīng)該是res.status陌兑,去掉括號沈跨,獲取狀態(tài)響應(yīng)碼,比如200
print res.read()
conn.close()