模拟登录,网站源码里面有几个隐藏的input流水号,获取到模拟post请求就是登录不了。

private string getMatch(string text, Regex reg)
{
Match mBody = reg.Match(text);
return mBody.Value;
}
private void btnLogin_Click(object sender, EventArgs e)
{
HttpClient httpClient = new HttpClient();
httpClient.MaxResponseContentBufferSize = 256000;
httpClient.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
string url = "http://ehire.51job.com/MainLogin.aspx";
HttpResponseMessage response = httpClient.GetAsync(new Uri(url)).Result;
string result = response.Content.ReadAsStringAsync().Result;
string ctmName = "会员名";
string userName = "账号";
string password = "密码";
string checkCode = string.Empty;
string isRememberMe = "false";
string returl = string.Empty;
Regex reg = new Regex(@"(?<=id=""hidLangType"" value="").*(?="")");
Regex reg1 = new Regex(@"(?<=id=""hidAccessKey"" value="").*(?="")");
Regex reg2 = new Regex(@"(?<=id=""fksc"" value="").*(?="")");
Regex reg3 = new Regex(@"(?<=id=""hidEhireGuid"" value="").*(?="")");
string langtype = getMatch(result, reg);
string oldAccessKey = getMatch(result, reg1);
string sc = getMatch(result, reg2);
string ec = getMatch(result, reg3);
HttpContent postContent = new FormUrlEncodedContent(new Dictionary()
{
{"ctmName", ctmName},
{"userName", userName},
{"password", password},
{"checkCode", checkCode},
{"oldAccessKey", oldAccessKey},
{"langtype", langtype},
{"isRememberMe", isRememberMe},
{"sc", sc},
{"ec", ec},
{"returl", returl}
});
response = httpClient.PostAsync(new Uri(url), postContent).Result
result = response.Content.ReadAsStringAsync().Result;
txtResult.Text = result;
httpClient.Dispose();
}
一直停留在登陆页面进不了后面,怎么解决啊?

1个回答

你好,类似情况流水号每次调用都是不一样的,对应的我们可以在其JavaScript的处理中找得到。
类比于CSDN登陆的时候所需的流水号,就是使用JS控制的,这里仅仅是给你一个思路吧,希望对你有用:-)

HD908571842
Elizabeths 你好,JS里面写的只有接收跟生成POST请求的处理,没有控制流水号变动的处理。这是个aspx页面,处理可能写在后台看不到到。问一下还有什么办法可以试一试?
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!