该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#登录的主页面
hosturl = 'http://localhost:8080//epay/login/login.do'
#post数据接收和处理的页面(我们要向这个页面发送我们构造的Post数据)
posturl = 'http://localhost:8080/epay/homepage.do'
#设置一个cookie处理器,它负责从服务器下载cookie到本地,并且在发送请求时带上本地的cookie
cj = cookielib.LWPCookieJar()
cookie_support = urllib2.HTTPCookieProcessor(cj)
opener = urllib2.build_opener(cookie_support, urllib2.HTTPHandler)
urllib2.install_opener(opener)
#打开登录主页面(他的目的是从页面下载cookie,这样我们在再送post数据时就有cookie了,否则发送不成功)
h = urllib2.urlopen(hosturl)
#构造header,一般header至少要包含一下两项。这两项是从抓到的包里分析得出的。
headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
'Referer' : 'xxx',
'Host':'xxx'}
#构造Post数据,他也是从抓大的包里分析得出的。
postData = {'username':'xxx',
'password':'xxx',
'rememberme':'0'}
#需要给Post数据编码
postData = urllib.urlencode(postData)
#通过urllib2提供的request方法来向指定Url发送我们构造的数据,并完成登录过程
request = urllib2.Request(posturl, postData, headers)
response = urllib2.urlopen(request)
text = response.read()
print text
@RequestMapping(value = "/login.do", method = {RequestMethod.GET, RequestMethod.POST})
public void login(HttpServletRequest request, HttpServletResponse response) throws Exception {
String nameOrTel = ReqUtil.getString(request, "username", "");
String pwd = ReqUtil.getString(request, "password", "");
int rememberme = ReqUtil.getInt(request, "rememberme", 0);
pwd = EncryptUtils.aesDecrypt(pwd);
进入接口后,后台接受的参数都为null