I have thousand proxies and thousand custom cookies.
Now I want to send requests with random proxy and using random cookie per request. I have tried to create new httpClientHandler
and httpClient
each time, but end up using all of my memory of my system.
After reading this article I understand I should reuse the same httpClient
. But nor the properties of httpClient
and httpClientHandler
cannot be modified after the first request.
This instance has already started one or more requests. Properties can only be modified before sending the first request.
So I have used to change the webProxy.Address
for changing proxy before sending requests. It works well but failed in the situation of multi-threading. It ends up using wrong proxy for the request. Any other ways to achieve my goal? THANKS.
Addtional Reference: HttpClientHandler / HttpClient Memory Leak
Quote from other users in the above reference:
Thanks for getting to the bottom of this. Unfortunately the HttpClient class does not meet my requirements then - due to the dynamic and unstable nature of public proxies, the objects HAVE to be often re-created. It appears HttpClient is just not a feasible solution for short-living connections -- changing the proxy settings requires re-constructing the HttpClientHandler, and thus the HttpClient. Either way, the objects should be able to live as long or short as needed without leaking; this definitely seems to be a flaw in the HttpClient.