Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing HttpMessageHandler in HttpClient

Tags:

c#

http

HttpClient takes an HttpMessageHandler argument in two of its constructors.

Is there any easy way to change the handler after the HttpClient has been created without creating a new HttpClient instance?

like image 779
Gigi Avatar asked Apr 10 '14 06:04

Gigi


1 Answers

If you keep a reference to the actual Handler, then you can modify the Handler after it has been created and inserted into the HttpClient. Not sure if you can change it to another Handler type however.

It's pretty dumb that you cannot retrieve the Handler through the HttpClient reference, such as HttpClient.Handler, but what I mentioned above works.

like image 194
TheGateKeeper Avatar answered Oct 15 '22 11:10

TheGateKeeper