httplib是python自带的模块,无需额外安装
#!/usr/bin/env python #coding:utf8 import httplib if __name__ == "__main__": conn = httplib.HTTPConnection('www.google.com',80) #conn.set_debuglevel(2) conn.request('GET','',headers={"Host": "www.google.com", "User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1) Gecko/20090624 Firefox/3.5", "Accept": "text/plain"}) respond = conn.getresponse() #输出状态码 print "status: %s" % respond.status #输出当次请求的结果的表述内容,200是ok,404是Not Found print "reason: %s" % respond.reason #关闭连接 conn.close()