HttpClient (IHttpClientFactory) + Proxy implementation with Dependency injection support and https://free-proxy-list.net/ as proxy-list source for .NET Standard 2.0 (netstandard2.0).
Library Checks:
- transparency (with reverse-IP check at: http://www.whatismyip.cz/)
- HTTPS (with access to: http://www.google.com/)
- measure elapsed time in miliseconds
For proxy Parse & Check use (test: BasicTest.cs):
// get proxy listvarproxies=awaitFreeProxyListNet.Parse();// check all proxiesvarcheckedProxies=awaitFreeProxyListNet.Check(proxies,codeFilter:new[]{"DE","PL"},required:1,maxMiliseconds:1200);Or use it all together by Dependency injection init procedure (example at: TestFixture.cs).
// parse & check proxies ; save it into configurationOptions.CheckAndAssignToConfig(codeFilter:new[]{"SE","DE","ES","PL"},required:2);// proxy client, with all proxies gets by CheckAndAssignToConfigservices.AddHttpClientProxy("PROXY",Options);And then use build-in clientHttpProxyClient.cs (test: BasicTest.cs)
varfactory=_test.Services.GetRequiredService<HttpProxyFactory>();varclient=factory.GetClientProxy("PROXY");varhtml=awaitclient.GetStringSafeAsync("https://httpstat.us");For common work with IHttpClientFactory clients, configure it by Dependency injection init procedure (example at: TestFixture.cs).
// common client, with all settings from Configurationservices.AddHttpClient("COMMON",Options);// common client, with retry = 5services.AddHttpClient("5RETRY",retry:5);// common client, with configured for retry when 404 status found (example)services.AddHttpClient("404TEST",Options,whenRetry: res =>res.StatusCode==HttpStatusCode.NotFound);Configuration example TestOptions.cs:
publicclassTestOptions:IHttpProxyConfiguration{publicintRetry=>2;publicintRetryFirstDelay=>1;publicboolGzipEnabled=>true;publicstringUserAgent=>HttpExtensions.DEFAULT_AGENT;publicIHttpProxyServer[]Proxies{get;set;}}For update from version 1.0.x -> 1.1.x:
- ADD:
AddHttpClientandAddHttpClientProxyparameterwhenRetryforHttpClientretry settings - ADD:
CheckAndAssignToConfigswitch:throwWhenLessThanRequiredfor exc. when less than requied proxy found - ADD:
CheckAndAssignToConfigparameter:Timeoutfor timeout for checking all proxies - DEL:
IHttpProxyConfiguration.ProxyEnabledremoved (useAddHttpClientofAddHttpClientProxyinstead manually) - DEL:
HttpProxyClientremoved ; now useHttpExtensions(for common configuration and tasks) &HttpProxyFactory(for work with proxy)