【发布时间】:2018-09-05 02:34:24
【问题描述】:
如何将一组 cookie 转换为 Cookie 对象?
var client = new HttpClient(handler);
var content = await client.GetAsync("http://example.com");
var cookies = content.Headers.GetValues("Set-Cookie");
我试过了,但是没用
var cliente = new RestClient("http://example.com");
cliente.CookieContainer = cookiesC; // CookieContainer cookiesC = new CookieContainer();
var parsedCookies = string.Join(";", cookies);
cookiesC.SetCookies(new Uri("http://example.com"), parsedCookies);
var res = cliente.Execute(new RestRequest("/", Method.GET));
如果我使用 httpClient 只是为了捕获 cookie 并在继续使用 restsharp 后不久。我正在寻找如何将 cookie 从 httpClient 传输到 RestSharp
【问题讨论】:
-
你用的是哪个?
HttpClient还是RestClient?您想要解决哪个问题? -
如果我使用 httpClient 只是为了捕获 cookie,然后很快就转到 RestClient。我正在寻找如何将 cookie 从 httpClient 传输到 RestClient
标签: c# cookies http-headers