Need to make a request to server which need specific cookies. Able to do this using HTTP client and handler with cookiecontainer. By using Typed clients, not able to find a way to set cookiecontainer.
Using httpclient:
var cookieContainer = new CookieContainer();
using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
using (HttpClient client = new HttpClient(handler))
{
//.....
// Used below method to add cookies
AddCookies(cookieContainer);
var response = client.GetAsync('/').Result;
}
Using HttpClientFactory:
In startup.cs
services.AddHttpClient<TypedClient>().
ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
{
CookieContainer = new CookieContainer()
});
In controller class
// Need to call AddCookie method here
var response =_typedclient.client.GetAsync('/').Result;
In Addcookie method, I need to add cookies to container. Any suggestions how to do this.