首页 新闻 赞助 找找看

C# httpWebrequest模拟登陆网站(有验证码)

0
悬赏园豆:60 [待解决问题]

C# httpWebrequest模拟登陆网站,已经写好post只提交了验证码cookie一直提示验证码验证失败!

https://user.qunar.com/passport/login.jsp?ret=http%3A%2F%2Ffuwu.qunar.com%2Fuserpass/clean

笔池的主页 笔池 | 初学一级 | 园豆:55
提问于:2017-08-02 17:03
< >
分享
所有回答(5)
0

验证码不是最新的?没代码啊?

顾晓北 | 园豆:10844 (专家六级) | 2017-08-02 17:14
0

public override void Login()
{
//https://ebooking.elong.com/ebkauth/login
var request00 = new RestRequest("/ebkauth/login");
request00.Method = Method.GET;
var response00 = _client.Execute(request00);
response00.Cookies.ToList().ForEach(t => Cookies.Add(new Cookie(t.Name, t.Value, t.Path, t.Domain)));

//http://ebooking.elong.com/ebkauth/verifycode/code?type=1&40
var request01 = new RestRequest($"ebkauth/verifycode/code?type=1&40");
request01.Method = Method.GET;
Cookies.ForEach(t => request01.AddCookie(t.Name, t.Value));
var response01 = _client.Execute(request01);
response01.Cookies.ToList().ForEach(t => Cookies.Add(new Cookie(t.Name, t.Value, t.Path, t.Domain)));
var vCode = response01.RawBytes.GetOrcString("3040", "1");

var request02 = new RestRequest("ebkauth/loginPost");
request02.Method = Method.POST;
request02.RequestFormat = DataFormat.Json;
Cookies.ForEach(t => request02.AddCookie(t.Name, t.Value));
request02.AddBody(new LoginInfo {freeLogin = true,username = OtaInfo.User,password = OtaInfo.Password,vcode = vCode});
var response02 = _client.Execute(request02);
LoginSuccessResult = JsonConvert.DeserializeObject<LoginSuccessResult>(response02.Content);
response02.Cookies.ToList().ForEach(t => Cookies.Add(new Cookie(t.Name, t.Value, t.Path, t.Domain)));

//ebkcommon/dashboard HTTP/1.1
var requestDashboard = new RestRequest("/ebkcommon/dashboard");
Cookies.ForEach(t => requestDashboard.AddCookie(t.Name, t.Value));
var responseDashboard = _client.Execute(requestDashboard);
responseDashboard.Cookies.ToList().ForEach(t => Cookies.Add(new Cookie(t.Name, t.Value, t.Path, t.Domain)));
var cookieValue = responseDashboard.Headers.FirstOrDefault(t => t.Name.Equals("Set-Cookie")).Value.ToString();
var nameLen = cookieValue.IndexOf('=');
var valueIndex = cookieValue.IndexOf("\"", nameLen + 3);
Cookies.Add(new Cookie(cookieValue.Substring(0,nameLen).Trim('='),$"\"{cookieValue.Substring(nameLen, valueIndex - nameLen).Trim('=').Trim('"')}\""));
Cookies.Add(new Cookie("hidePhoneVerify", $"{DateTime.Now:yyyy-MM-dd}/jzys028"));
Cookies.Add(new Cookie("zh_choose", "n"));
}

花飘水流兮 | 园豆:13560 (专家六级) | 2017-08-02 21:54

 参见如上,01为验证码图片。

支持(0) 反对(0) 花飘水流兮 | 园豆:13560 (专家六级) | 2017-08-02 21:56
0

不识别验证码,怎么登陆?

小小高 | 园豆:1095 (小虾三级) | 2017-08-04 12:31
0

模拟的请求,或许人家网站有相关的js进行bot验证,认为你是bot, 所以通过不了。你得继续研究目标站点。如果用webbrowser可以轻松模拟验证,然后拿到Cookie,想干什么都可以。

空明流光 | 园豆:106 (初学一级) | 2017-08-04 17:08
0

验证码错误的原因一般是没有处理cookies

兰冰点点 | 园豆:401 (菜鸟二级) | 2017-08-06 20:52
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册