虽然说httplib跟request比起来,用的人已经不多了,但是会写一个简单的demo还是有必要的,下面就是我初次下手写的demo,里面有一些错误,你能看出来吗?
coding=utf-8
import httplib
url = "http://www.baidu.com/"
host = "www.baidu.com"
location = "/"-------------------location在这里不是必须的
body = ''
method = "get"-----------------应该用大写的‘GET’
headers = {}
conn = httplib.HTTPConnection(host)
conn.request(method, url, body, headers)
res = conn.getresponse()
print res.status()--------------------应该是res.status,去掉括号,获取状态响应码,比如200
print res.read()
conn.close()