作者ansem (DoubleA)
看板C_Sharp
标题[问题] 无法使用AddHeader於ResClient取得资料
时间Thu Jan 19 17:35:50 2023
各位好,我目前遇到的问题是我想去证交所抓信用交易资料
使用以下的程式码
string url = "
https://wwwc.twse.com.tw/zh/exchangeReport/MI_MARGN";
var client = new RestClient(url);
var request = new RestRequest("",Method.Get);
request.AddHeader("Accept", "*/*");
request.AddHeader("Accept-Encoding", "gzip, deflate, br");
request.AddHeader("Accept-Language",
"zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7");
request.AddHeader("Connection", "keep-alive");
request.AddHeader("Content-Length", "42");
request.AddHeader("Content-Type",
"application/x-www-form-urlencoded; charset=UTF-8");
request.AddHeader("Cookie", "_ga=_ga=GA1.3.228088691.1674099947;
_gid=GA1.3.1638277859.1674099947;
JSESSIONID=E0D3F21B26722058423036EA82A061FE; _gat=1");
request.AddHeader("Host", "wwwc.twse.com.tw");
request.AddHeader("Origin", "
https://wwwc.twse.com.tw");
request.AddHeader("Referer",
"
https://wwwc.twse.com.tw/zh/page/trading/exchange/MI_MARGN.html");
request.AddHeader("sec-ch-ua", "'Not_A Brand';v='99', 'Google
Chrome';v='109', 'Chromium';v='109'");
request.AddHeader("sec-ch-ua-mobile", "?0");
request.AddHeader("sec-ch-ua-platform", "'Windows'");
request.AddHeader("Sec-Fetch-Dest", "empty");
request.AddHeader("Sec-Fetch-Mode", "cors");
request.AddHeader("Sec-Fetch-Site", "same-origin");
request.AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0;
Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0
Safari/537.36");
request.AddHeader("X-Requested-With", "XMLHttpRequest");
RestResponse response = client.Execute(request);
AddInfo(response.Content.ToString());
但是会一直出现回传是null的状态,但是我使用开发人员工具来看这是我在取得分类项目"全部"的需求header,请问这里面是否有我漏掉的部分呢?
感谢各位的解惑
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 42.73.197.230 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_Sharp/M.1674120953.A.E8F.html
1F:推 nicetw20xx: 有response code吗 01/25 17:54
2F:→ nicetw20xx: 另外一样的request用postman打会有结果吗 01/25 17:54
3F:→ ssccg: 明明是GET为什麽会有Content-Length、Content-Type? 01/26 23:51
4F:→ ssccg: 你知不知道Header的意义啊... 01/26 23:51
5F:→ ssccg: 说不定是对方server还在等你说好的42个bytes在哪呢 01/26 23:52
7F:→ ssccg: 这网址直接开都有东西了,根本不用那麽多Header 01/26 23:52