[問題] 無法使用AddHeader於ResClient取得資料
各位好,我目前遇到的問題是我想去證交所抓信用交易資料
使用以下的程式碼
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://www.ptt.cc/bbs/C_Sharp/M.1674120953.A.E8F.html
推
01/25 17:54,
1年前
, 1F
01/25 17:54, 1F
→
01/25 17:54,
1年前
, 2F
01/25 17:54, 2F
→
01/26 23:51,
1年前
, 3F
01/26 23:51, 3F
→
01/26 23:51,
1年前
, 4F
01/26 23:51, 4F
→
01/26 23:52,
1年前
, 5F
01/26 23:52, 5F
→
01/26 23:52,
1年前
, 6F
01/26 23:52, 6F
→
01/26 23:52,
1年前
, 7F
01/26 23:52, 7F
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章