pythonのhttplibなどのパッケージ
1046 ワード
python 2を使う.7 fパッケージのhttplib,urllibなどのパケットは,httpリクエストを送信する.
#coding=gbk
import httplib
import urllib
import 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()