使用httplib,进行POST请求
(2009-08-13 00:08:43)
标签:
it |
分类: 编程知识 |
def query(self):
try:
url = httplib.urlsplit(self.url)
conn = httplib.HTTPConnection(url.netloc)
conn.connect()
#conn.set_debuglevel(1)
if self.data:
conn.putrequest("POST", self.url)
conn.putheader("Content-Length", len(self.data))
conn.putheader("Content-Type",
"application/x-www-form-urlencoded")
else:
conn.putrequest("GET", self.url, None)
conn.putheader("Content-Length", 0)
conn.putheader("Connection", "close")
conn.endheaders()
if self.data:
conn.send(self.data)
f = conn.getresponse()
if f:
self.response = f.read()