如何将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
答案 0 :(得分:0)
您需要这样声明您的HttpClient
:
CookieContainer cookiesC= new CookieContainer();
HttpClientHandler handler = new HttpClientHandler();
handler.CookieContainer = cookiesC;
HttpClient client = new HttpClient(handler);
这将导致HttpClient
使用cookiesC
容器,然后您可以(似乎)将其与RestClient
一起使用。