验证码不是最新的?没代码啊?
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"));
}
参见如上,01为验证码图片。
不识别验证码,怎么登陆?
模拟的请求,或许人家网站有相关的js进行bot验证,认为你是bot, 所以通过不了。你得继续研究目标站点。如果用webbrowser可以轻松模拟验证,然后拿到Cookie,想干什么都可以。
验证码错误的原因一般是没有处理cookies