python的httplib等包

来源:互联网 发布:minitab软件免费下载 编辑:程序博客网 时间:2024/06/17 07:25

用python2.7f封装的httplib, urllib等包,发送http请求

#coding=gbkimport httplibimport urllibimport sys conn = httplib.HTTPConnection("www.python.org") conn.request("GET","/index.html")r1 = conn.getresponse()print r1.status, r1.reason conn.close()sys.exit(0)params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}#conn = httplib.HTTPConnection("www.python.org")#conn = httplib.HTTPConnection("127.0.0.1:8000")conn = httplib.HTTPConnection("192.168.1.113:8000")conn.request("POST", "/", params, headers)r3 = conn.getresponse()print r3.status, r3.reason, r3.read() conn.close()sys.exit(0)conn = httplib.HTTPConnection("www.python.org")conn.request("HEAD", "/index.html")r2 = conn.getresponse()print r2.status, r2.reason, r2.read() conn.close()


0 0
原创粉丝点击