-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest2.py
More file actions
53 lines (37 loc) · 1.29 KB
/
test2.py
File metadata and controls
53 lines (37 loc) · 1.29 KB
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
#!/usr/bin/python
# coding=utf-8
import cookielib
import urllib
import urllib2
def sendRequest(posturl, postData, headers):
postData = urllib.urlencode(postData)
request = urllib2.Request(posturl, postData, headers)
response = urllib2.urlopen(request)
text = response.read()
return text
def sendQuery(url, postData):
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1'}
text = sendRequest(url, postData, headers)
return text
def login(hosturl, username, password):
posturl = hosturl + '/login'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1',
'Referer': posturl}
postData = {
'userName': username,
'password': password
}
text = sendRequest(posturl, postData, headers)
return text
def init():
cj = cookielib.LWPCookieJar()
cookie_support = urllib2.HTTPCookieProcessor(cj)
opener = urllib2.build_opener(cookie_support, urllib2.HTTPHandler)
urllib2.install_opener(opener)
h = urllib2.urlopen(hosturl)
if __name__ == "__main__":
# hosturl = 'http://10.73.37.63:8080'
hosturl = 'http://localhost:8080'
init()
login(hosturl, "zhongsf", "123456")
# 封装所有请求url和参数,