相关疑难解决方法(0)

HttpClient不保存Cookie

我正在使用新的HttpClient来处理我项目的网上冲浪需求; 但是,尽管设置正确,但HttpClient不会将cookie保存到Cookie容器中,并且它始终为EMPTY.

private CookieContainer _cookieContainer = new CookieContainer();
private HttpClient HttpClient { get; set; }
private HttpClientHandler HttpClientHandler { get; set; }

public Initialize()
{
    HttpClientHandler = new HttpClientHandler
                            {
                                AllowAutoRedirect = true,
                                UseCookies = true,
                                CookieContainer = _cookieContainer
                            };
    HttpClient = new HttpClient(HttpClientHandler);
}

public CookieContainer Cookies
{
    get { return _cookieContainer; }
    set { _cookieContainer = value; }
}

public void TEST()
{
    //This is always empty, although I am sure that the site is saving login …
Run Code Online (Sandbox Code Playgroud)

c# dotnet-httpclient

12
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

dotnet-httpclient ×1