-
Notifications
You must be signed in to change notification settings - Fork 0
/
UrlHelper.py
72 lines (56 loc) · 1.42 KB
/
UrlHelper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#-*- encoding:utf-8 -*-
'''
Created on 2012-3-27
@author: zhangdong
'''
import urllib2
import urllib
import JsonHelper
from ApiError import APIError;
from urllib2 import HTTPError
'''
获取url内容
'''
def getInfoByUrl(url):
print url;
print "aaa"
try:
response=urllib2.urlopen(url);
except HTTPError as e:
raise APIError(e.code,e.msg,"");
html=response.read();
return html;
'''
提交内容
'''
def postInfo(url,params):
request = urllib2.Request(url,urllib.urlencode(params));
response = urllib2.urlopen(request);
result=response.read();
print result;
return result;
'''
获取某一请求的状态
'''
def getGetUrlData(url):
return JsonHelper.getDataByJson(getInfoByUrl(url));
def getPostUrlData(url,params):
return JsonHelper.getDataByJson(postInfo(url,params));
def getInfoByRequest(request):
try:
response=urllib2.urlopen(request);
except HTTPError as e:
raise APIError(e.code,e.msg,"");
html=response.read();
return html;
def getGetRequestData(request):
return JsonHelper.getDataByJson(getInfoByRequest(request));
def postInfoByRequest(request):
try:
response = urllib2.urlopen(request);
except HTTPError as e:
raise APIError(e.code,e.msg,"");
result=response.read();
return result;
def getPostByRequestData(request):
return JsonHelper.getDataByJson(postInfoByRequest(request));