服務器內部錯誤,通常因請求參數不合法(缺少必要字段、格式錯誤、簽名驗證失敗)導致後端拋出未捕獲異常。
HttpWebRequest 的所有 Header:
User-Agent(必須與瀏覽器一致)Referer(登錄頁 URL)Origin、Content-Type、Accept、Accept-Language 等_token、csrf_token、_t 等動態字段,**必須先 GET 登錄頁解析 HTML 獲取**,再攜帶提交 POST。CookieContainer 自動處理 Set-Cookie/重定向 Cookie。Encoding.UTF8.GetBytes(postData) 對應 Content-Type: application/x-www-form-urlencoded; charset=UTF-8。// 1. 先 GET 登錄頁獲取動態 token
string loginPage = GetHtml(loginUrl, cookieContainer, header);
string token = Regex.Match(loginPage, "name=\"_token\" value=\"([^\"]+)\"").Groups[1].Value;
// 2. POST 登錄攜帶所有字段
string postData = $"email={Uri.EscapeDataString(email)}&password={Uri.EscapeDataString(pwd)}&_token={token}";
byte[] postBytes = Encoding.UTF8.GetBytes(postData);
request.ContentLength = postBytes.Length;
// ... 寫入流、獲取響應
await url.PostUrlEncodedAsync(data).ReceiveString()。