浏览器请求登录如下
POST http://127.0.0.1/userLogin.asp HTTP/1.1
Host: 127.0.0.1
Connection: Keep-Alive
Content-Length: 79
Pragma: no-cache
Cache-Control: no-cache
Accept: image/jpeg, image/gif, image/pjpeg, application/x-ms-application, application/xaml+xml, application/x-ms-xbap, */*
Accept-Language: zh-CN
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; SE 2.X MetaSr 1.0)
Referer: http://127.0.0.1/userLogin.asp
Accept-Encoding: gzip, deflate
save2Cookie=&vldcode=&account=admin&password=fgs@mm&btnSubmit=+%B5%C7%C2%BC+
我 py 写成这样
login_url = "http://127.0.0.1/userLogin.asp"
admin_url = "http://127.0.0.1/menu_admin.asp"
headers1 = {
"Accept-Encoding":"gzip, deflate",
"Host":"127.0.0.1",
"Referer":"http://10.41.10.254/menu_admin.asp",
"Upgrade-Insecure-Requests":"1",
"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36",
"Content-Type": "application/x-www-form-urlencoded",
}
data1 = {
"save2Cookie":"","vldcode":"","account":"admin","password":"fgs@mm","btnSubmit":"登录"
}
data_gb2312 = urlencode(data1, encoding='gb2312')
sesion = requests.session()
sesion.post(url=login_url,headers=headers1,data=data_gb2312)
aa=sesion.get(admin_url)
print(aa.content.decode("gb2312"))
我用 fd 看到我请求是这样的
POST http://127.0.0.1/userLogin.asp HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36
Accept-Encoding: gzip, deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Connection: keep-alive
Accept-Language: zh-CN,zh;q=0.9
Cache-Control: no-cache
Host: 127.0.0.1
Pragma: no-cache
Connection: keep-alive
Referer: http://127.0.0.1/home.asp
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
Content-Length: 79
save2Cookie=&vldcode=&account=admin&password=fgs%40mm&btnSubmit=%B5%C7%C2%BC
是我的构造有问题吗?还是接口不对,我发现%B5%C7%C2%BC 正常请求 是有个+ 号的,各位帮忙看看,一个路由登录