Dưới đây là các mã:Làm thế nào tôi có thể nhận cookie từ HttpClientHandler.CookieContainer
public static async Task<string> DownloadPageWithCookiesAsync(string url)
{
HttpClientHandler handler = new HttpClientHandler();
handler.UseDefaultCredentials = true;
handler.AllowAutoRedirect = true;
handler.UseCookies = true;
handler.CookieContainer = new CookieContainer();
HttpClient client = new HttpClient(handler);
HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
string responseBody = response.Content.ReadAsString();
return responseBody;
}
sau client.GetAsync(url);
chạy, các handler.CookieContainer
chứa 7 cookie. Tôi có thể truy cập chúng bằng cách nào?
'tuyên bố foreach không thể hoạt động trên các biến của loại 'System.Net.CookieContainer' vì 'System.Net.CookieContainer' không chứa một định nghĩa nào cho 'GetEnumerator'' –
Sử dụng vòng lặp for thay vào đó nhận được chúng? –
Cảm ơn nhưng Loop về những gì? Không có toán tử chỉ mục nào được xác định. –