GithubHelp home page GithubHelp logo

msigut / freeproxysharp Goto Github PK

View Code? Open in Web Editor NEW
19.0 19.0 0.0 60 KB

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

License: Apache License 2.0

C# 87.09% PowerShell 12.16% Batchfile 0.75%
free-proxy-list httpclient ihttpclientfactory netstandard20 proxy

freeproxysharp's Introduction

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 list
var proxies = await FreeProxyListNet.Parse();
// check all proxies
var checkedProxies = await FreeProxyListNet.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 configuration
Options.CheckAndAssignToConfig(codeFilter: new[] { "SE", "DE", "ES", "PL" }, required: 2);

// proxy client, with all proxies gets by CheckAndAssignToConfig
services.AddHttpClientProxy("PROXY", Options);

And then use build-in client HttpProxyClient.cs (test: BasicTest.cs)

var factory = _test.Services.GetRequiredService<HttpProxyFactory>();
var client = factory.GetClientProxy("PROXY");
var html = await client.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 Configuration
services.AddHttpClient("COMMON", Options);
// common client, with retry = 5
services.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:

public class TestOptions : IHttpProxyConfiguration
{
	public int Retry => 2;
        public int RetryFirstDelay => 1;
        public bool GzipEnabled => true;
        public string UserAgent => HttpExtensions.DEFAULT_AGENT;
	
        public IHttpProxyServer[] 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)

freeproxysharp's People

Contributors

msigut avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.