123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import sys
- if (sys.version_info.major == 3):
- from urllib import parse
- import urllib.request as urllib2
- else:
- import urllib2
- class HttpUtil(object):
-
- @staticmethod
- def post(url, postData):
- req = urllib2.Request(url, data=postData.encode('utf-8'),
- headers={'Content-Type': 'application/json;charset=UTF-8'})
- res = urllib2.urlopen(req, timeout=60).read().decode("utf-8")
- return res
-
- @staticmethod
- def postText(url, postData):
- req = urllib2.Request(url, data=postData.encode('utf-8'),
- headers={'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'})
- res = urllib2.urlopen(req, timeout=60).read().decode("utf-8")
- return res
-
- @staticmethod
- def get(url, getData, isquote):
- if isquote:
- getData = parse.quote(getData)
- req = urllib2.Request((url + getData), headers={'Content-Type': 'text/xml;charset=UTF-8'})
- res = urllib2.urlopen(req, timeout=60)
- req = res.read()
- return req.decode()
-
-
-
|