I'm little confused about HttpClient. At the moment I'm using single instance of this class in my whole application.
However it seems, that it doesn't allow me to set, for example AllowAutoRedirect option specifically for some requests.
Is HttpClient designed to be instantiated for every other request? I'm talking about multithreaded environment. Maybe I should wrap it in more flexible class structure?
To change any properties per request, then yes, you will need to create a new instance of HttpClient
. Obviously, performance and resources can play a factor if you're building a high-performance application with many requests due to creating the object multiple times.
Creating a wrapper class for HttpClient
would be beneficial if you do go down this route and in any case, you can pass HttpClient
as a parameter if you wish to change to a single instance.
HttpClient
in most cases should be used as one instance as you can call as many requests as you like and the object has all the tools to handle async and responses. This is the same for request types WebRequest
and HttpWebRequest
.
If you need to receive a 200 OK status before starting another, managing those situations is extremely easy with one instance compared to creating your own queue functionality.