2 回答

TA貢獻1801條經驗 獲得超16個贊
如果您不設置,HttpClient 將吃掉自定義UseCookiescookie false,
using (var handler = new HttpClientHandler { UseCookies = false })
using (client = new HttpClient(handler) { BaseAddress = new Uri(Path) }){
client.DefaultRequestHeaders.Add("cookie", cookieValue);
}
它將嘗試使用 cookie 容器,同時忽略任何自定義 cookie 標頭,如果你問我的話,這是非常令人沮喪的行為。

TA貢獻1812條經驗 獲得超5個贊
.Net Framework 使用 Cookie 容器。
同樣是核心,也許它是比您現在正在做的更好的實現并且得到更多支持。
小例子:
var cookieContainer = new CookieContainer();
? ? ? ? ? ? this.handler = new HttpClientHandler
? ? ? ? ? ? {
? ? ? ? ? ? ? ? CookieContainer = cookieContainer,
? ? ? ? ? ? ? ? UseCookies = true
? ? ? ? ? ? };
? ? ? ? ? ? client = new HttpClient(handler);
- 2 回答
- 0 關注
- 167 瀏覽
添加回答
舉報