1. [Code]get method
Import Httplib
#-----------------------------
conn = Httplib. Httpconnection ("www.python.org")
Conn.request ("GET", "/index.html")
R1 = Conn.getresponse ()
Print R1.status, R1.reason
$ OK
Data1 = R1.read ()
Conn.request ("GET", "/parrot.spam")
r2 = Conn.getresponse ()
Print R2.status, R2.reason
404 Not Found
Data2 = R2.read ()
Conn.close ()
2. [Code]head method
Import Httplib
#-----------------------------
conn = Httplib. Httpconnection ("www.python.org")
Conn.request ("HEAD", "/index.html")
res = Conn.getresponse ()
Print Res.status, Res.reason
06200 OK
data = Res.read ()
Print len (data)
090
data = = "
True
3. [Code]post method
Import Httplib, Urllib
#-----------------------------
params = Urllib.urlencode ({' spam ': 1, ' eggs ': 2, ' bacon ': 0})
headers = {"Content-type": "application/x-www-form-urlencoded",
... "Accept": "Text/plain"}
conn = Httplib. Httpconnection ("musi-cal.mojam.com:80")
Conn.request ("POST", "/cgi-bin/query", params, headers)
Response = Conn.getresponse ()
Print Response.Status, Response.reason
09200 OK
data = Response.read ()
Conn.close () A
Reprint: Python sends an HTTP request