如何将一组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
:
CookieContainer cookiesC= new CookieContainer();
HttpClientHandler handler = new HttpClientHandler();
handler.CookieContainer = cookiesC;
HttpClient client = new HttpClient(handler);
这将导致HttpClient
使用cookiesC
容器,然后您可以使用(看似)与RestClient
。