|
楼主 |
发表于 2016-10-18 21:17:35
|
显示全部楼层
浏览器抓到的:
General
Request URL:https://www.mdnsonline.com/customer/login
Request MethodOST
Status Code:302 Found
Remote Address:203.135.139.118:443
===============================================
Request Headers:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, br
Accept-Language:zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4,ja;q=0.2,ko;q=0.2
Cache-Control:no-cache
Connection:keep-alive
Content-Length:166
Content-Type:application/x-www-form-urlencoded
Cookie: _csrf-frontend=5e84f0fb85d48aa83f28325ac4480ef68c8ab5491948a61b4a227fa4fc8b6ee9a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22dnZTOwxwIGE3geJE32xBz6gg0OHU9lyI%22%3B%7D; mdnsonline=8rfs3erh01jbsjampv3r5pc170;
DNT:1
Host:www.mdnsonline.com
Origin:https://www.mdnsonline.com
Pragma:no-cache
Referer:https://www.mdnsonline.com/customer/login
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36
=========================================
Form Data:
_csrf-frontend:TkZiRENmQXoqKDgQDBE5DQcBJ3ckAws/fXQaBjlQJh1.CSoRego4Mw==
CustomerLoginForm[email]:username@qq.com
CustomerLoginForm[password]:password
其中cookie是之前GET这个网页获得的,token的值是GET页面里面的一个参数
用框架的代码:
string csrf_token = Regex.Match(loresult.Html, @"(?<=name=""csrf-token"" content="").*?(?=\"">)").ToString();// 从之前GET的页面获取这个token的值
sb.Append("_csrf-frontend="); sb.Append(System.Web.HttpUtility.UrlEncode(csrf_token)); sb.Append("&");
sb.Append("CustomerLoginForm%5Bemail%5D="); sb.Append(taskDetails.tbUserName); sb.Append("&");
sb.Append("CustomerLoginForm%5Bpassword%5D="); sb.Append(taskDetails.tbPwd);
myPostData = sb.ToString();
sb.Length = 0;
string filename = System.AppDomain.CurrentDomain.BaseDirectory + "sup.cer";
loitem = new HttpItem()
{
URL = "https://www.mdnsonline.com/customer/login",
Method = "OST",
Postdata = myPostData,
Timeout = 100000,//连接超时时间 可选项默认为100000
ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000
UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36",//用户的浏览器类型,版本,操作系统 可选项有默认值
Host = "www.mdnsonline.com",
Referer = "https://www.mdnsonline.com/customer/login",
ContentType = "application/x-www-form-urlencoded",
Accept = "text/html,application/xhtml+xml,*/*",
CookieCollection = cc_cookie,
//Expect100Continue = true,
CerPath = filename,
Allowautoredirect = true,
};
loitem.Header.Add("ragma", "no-cache");
loitem.Header.Add("Cache-Control", "no-cache");
loitem.Header.Add("Upgrade-Insecure-Requests", "1");
//loitem.Header.Add("Connection", "keep-alive");
//得到HTML代码
loresult = lohttp.GetHtml(loitem);
其中,myPostData的数据跟Form Data的内容已经是一模一样了。
整个登录过程只有这一个post。
成功登录的话是302
我上面的代码登录就是返回badrequest。。
飞哥要是不嫌麻烦的话就帮我看看。要是忙的话就算了。 |
|