本帖最后由 yi_shu 于 2018-5-15 16:22 编辑
[C#] 纯文本查看 复制代码 HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "https://m.zdao.com/",
Method = "get",
Host = "m.zdao.com",
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36",
};
HttpResult result = http.GetHtml(item);
string cookies = result.Cookie;
string id = textBox1.Text;
string csrf_token = cookies.Split(';')[4].Split('=')[1];
string postData = $"id={id}&cpid=57c3ed6ba45daef88f10a1d5ef684d40&account_type=cc&csrf_token={csrf_token}";
HttpItem httpItemGet = new HttpItem()
{
URL = "https://m.zdao.com/addrlist/get_evaluate",
Method = "post",
Host = "m.zdao.com",
Accept = "application/json, text/javascript, */*; q=0.01",
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36",
ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
Referer = item.URL,
Postdata = postData,
Cookie = cookies,
};
httpItemGet.Header.Add("Origin", "https://m.zdao.com");
httpItemGet.Header.Add("X-Requested-With", "XMLHttpRequest");
httpItemGet.Header.Add("Accept-Encoding", "gzip, deflate, br");
httpItemGet.Header.Add("Accept-Language", "zh-CN,zh;q=0.9");
// httpItemGet.Header.Add("X-CSRF-Token", csrf_token);
HttpResult httpResultget = http.GetHtml(httpItemGet);
先上代码,要请求的是https://m.zdao.com/addrlist/get_evaluate这个接口,直接请求返回404错误,后来发觉提交的cookies里要带有csrf_token,所以先请求一次主页面,获取到csrf_token,但是这次请求返回的是csrf_token过期,请各位大神支支招,抓取像这种页面时如何保证csrf_token不过期!我这里因为是测试的,取cookies里的csrf_token,直接取指定值了string csrf_token = cookies.Split(';')[4].Split('=')[1];,不要纠结我csrf_token取得不对,这个在我机器上是对的!
|