#!/user/bin/python
#coding=utf8
import httplib
class HttpUtil:
TIMEOUT=30
def __init__(self,url,method,service,data,headers={"Content-Type":"text/html;charset=UTF-8"},port=80):
self.url=url
self.method=method
self.service=service
self.data=data
self.headers=headers
self.port=port
def fetch(self):
httpConn=httplib.HTTPConnection(self.url,self.port,timeout=self.TIMEOUT)
try:
httpConn.request(self.method,self.service,self.data,self.headers)
resp=httpConn.getresponse()
if resp.status==200:
respData=resp.read()
return respData
else:
return None
except Exception,e:
print e