HttpClientHandler

HttpClient configuration is done using a HttpClientHandler, simply create an instance of the HttpClientHandler and pass it in the Config constructor or UseHttpClientHandler extension method.

More information on HttpClientHandler

Example using a HttpClientHandler to populate cookies from the response to it’s CookieContainer:

var cookieContainer = new CookieContainer();

var config = new Config()
      .UseHttpClientHandler(handler => handler.CookieContainer = cookieContainer);

dynamic restClient = new RestClient("https://httpbin.org/cookies", config);

When using IHttpClientFactory use the UseHttpClientHandler extension method when adding the RestClient to your .NET Core DI container (usually in Startup.cs):

var cookieContainer = new CookieContainer();

services
      .AddRestClient("https://httpbin.org/cookies")
      .UseHttpClientHandler(handler => handler.CookieContainer = cookieContainer);

Note you can only add one HttpClientHandler to the pipeline. The overloads taking a HttpClientHandler instance or Func<HttpClientHandler> are obsolete - use the Action<HttpClientHandler> overloads shown above.

For cookies specifically it’s easier to use the CookieHandler.

Updated: