gpt4 book ai didi

c# - 如何从 HttpClientHandler.CookieContainer 获取 cookie

转载 作者:太空狗 更新时间:2023-10-29 22:53:57 24 4
gpt4 key购买 nike

代码如下:

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;
}

client.GetAsync(url); 运行后,handler.CookieContainer 包含 7 个 cookie。我如何访问它们?

最佳答案

使用 CookieContainer 的 GetCookies 方法,指定您想要 cookie 的 URI。它返回一个您可以枚举的 CookieCollection。

关于c# - 如何从 HttpClientHandler.CookieContainer 获取 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8315251/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com