Skip to content

Repository files navigation

FreeProxySharp

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:

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;}}

Update notice

For update from version 1.0.x -> 1.1.x:

  • ADD: AddHttpClient and AddHttpClientProxy parameter whenRetry for HttpClient retry settings
  • ADD: CheckAndAssignToConfig switch: throwWhenLessThanRequired for exc. when less than requied proxy found
  • ADD: CheckAndAssignToConfig parameter: Timeout for timeout for checking all proxies
  • DEL: IHttpProxyConfiguration.ProxyEnabled removed (use AddHttpClient of AddHttpClientProxy instead manually)
  • DEL: HttpProxyClient removed ; now use HttpExtensions (for common configuration and tasks) & HttpProxyFactory (for work with proxy)

About

.NET Core Proxy library based on HttpClient works with FreeProxyList.net

Topics

Resources

Stars

20 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages