Leaf.xNet - provides HTTP/HTTPS, Socks 4A, Socks 4, Socks 5.
It's a based on Extreme.Net. And original library xNet.
Usage same like original xNet.
Telegram: @kelog
E-Mail: mixtape774@gmail.com
- Artem (devspec) - donation support. Thank you
- Igor' Vasilyev - found many bugs and reported it. Thank you
- Monaco (BHF) - bug reporter, donations help
- Wizard - donation support
- @azor83 - donation for implementation of MiddleHeaders
- TMT - donation for PATCH, DELETE, PUT, OPTIONS methods
- guzlewski: Randomizer fixes, IgnoreInvalidCookies
Installation via NuGet
Install-Package Leaf.xNet
- GET
- POST
- PATCH
- DELETE
- PUT
- OPTIONS
Not maintained in public Leaf.xNet anymore.
But you can order private paid Leaf.xNet with support.
Telegram: @kelog
See demo project in the Examples folder.
usingLeaf.xNet.Services.Cloudflare;// Check and pass CloudFlare JS Challange if it's present// Attention: It's working when Re-Captcha enabledvarhttpRequest=newHttpRequest();varclearResp=httpRequest.GetThroughCloudflare("https://...");// Check only (without solution)varresp=httpRequest.Get("https://...");boolisCloudFlared=resp.isCloudFlared();See demo project in the Examples folder.
usingLeaf.xNet.Services.Captcha;// You can use: RucaptchaSolver | TwoCaptchaSolver | CapmonsterSolverhttp.CaptchaSolver=newRucaptchaSolver{ApiKey="your_key",// If you need to use Proxy (Recaptcha for example) - uncomment the line below// Proxy = new CaptchaProxy(CaptchaProxyType.HTTPS, "80.81.82.83:8080"),// // ProxyTypes: CaptchaProxyType.HTTP || HTTPS || SOCKS4 || SOCKS5};varclearResp=httpRequest.GetThroughCloudflare("https://...");It's enabled by default. But you can disable this behavior:
httpRequest.KeepTemporaryHeadersOnRedirect=false;httpRequest.AddHeader(HttpHeader.Referer,"https://google.com");httpRequest.Get("http://google.com").None();// After redirection to www.google.com - request won't have Referer header because KeepTemporaryHeadersOnRedirect = falsehttpRequest.EnableMiddleHeaders=true;// This requrest has a lot of redirectsvarresp=httpRequest.Get("https://account.sonyentertainmentnetwork.com/");varmd=resp.MiddleHeaders;Used native cookie storage from .NET with domain shared access support.
Cookies enabled by default. If you wait to disable parsing it use:
HttpRequest.UseCookies=false;Cookies now escaping values. If you wait to disable it use:
HttpRequest.Cookies.EscapeValuesOnReceive=false;// UnescapeValuesOnSend by default = EscapeValuesOnReceive// so set if to false isn't necessaryHttpRequest.Cookies.UnescapeValuesOnSend=false;// By Default (SSL 2 & 3 not used)httpRequest.SslProtocols=SslProtocols.Tls|SslProtocols.Tls12|SslProtocols.Tls11;Sometimes HTTPS proxy require relative address instead of absolute. This behavior can be changed:
http.Proxy.AbsoluteUriInStartingLine=false;UserAgents were updated in January 2019.
httpRequest.UserAgentRandomize();// Call it again if you want change it again// or set propertyhttpRequest.UserAgent=Http.RandomUserAgent();When you need a specific browser just use the Http class same way:
ChromeUserAgent()FirefoxUserAgent()IEUserAgent()OperaUserAgent()OperaMiniUserAgent()
varurlParams=newRequestParams{{["привет"]="мир"},{["param2"]="val2"}}// Or// urlParams["привет"] = "мир";// urlParams["param2"] = "val2";stringcontent=request.Post("https://google.com",urlParams).ToString();stringtitle=html.Substring("<title>","</title>");// substring or defaultstringtitleWithDefault=html.Substring("<title>","</title>")??"Nothing";stringtitleWithDefault2=html.Substring("<title>","</title>",fallback:"Nothing");// substring or emptystringtitleOrEmpty=html.SubstringOrEmpty("<title>","</title>");stringtitleOrEmpty2=html.Substring("<title>","</title>")??"";// "" or string.EmptystringtitleOrEmpty3=html.Substring("<title>","</title>",fallback:string.Empty);// substring or thrown exception when not found// it will throw new SubstringException with left and right arguments in the messagestringtitleOrException=html.SubstringEx("<title>","</title>");// when you need your own ExceptionstringtitleOrException2=html.Substring("<title>","</title>")??throwMyCustomException();Add in the beggining of file.
usingLeaf.xNet;And use one of this code templates:
using(varrequest=newHttpRequest()){// Do something}// OrHttpRequestrequest=null;try{request=newHttpRequest();// Do something }catch(HttpExceptionex){// Http error handling// You can use ex.Status or ex.HttpStatusCode for more details.}catch(Exceptionex){// Unhandled exceptions}finally{// Cleanup in the end if initializedrequest?.Dispose();}Methods AddField() and AddFile() has been removed (unstable).
Use this code:
varmultipartContent=newMultipartContent(){{newStringContent("Harry Potter"),"login"},{newStringContent("Crucio"),"password"},{newFileContent(@"C:\hp.rar"),"file1","hp.rar"}};// When response isn't requiredrequest.Post("https://google.com",multipartContent).None();// Orvarresp=request.Post("https://google.com",multipartContent);// And then read as stringstringrespStr=resp.ToString();stringhtml=request.Get("https://google.com").ToString();stringtitle=html.Substring("<title>","</title>");varhttpResponse=httpRequest.Get("https://yoursever.com");stringresponseHeader=httpResponse["X-User-Authentication-Token"];varresp=request.Get("http://google.com/file.zip");resp.ToFile("C:\\myDownloadedFile.zip");stringresponse=request.Get("https://twitter.com/login").ToString();varcookies=request.Cookies.GetCookies("https://twitter.com");foreach(Cookiecookieincookies){// concat your string or do what you wantConsole.WriteLine($"{cookie.Name}: {cookie.Value}");}Your proxy server:
// Type: HTTP / HTTPS httpRequest.Proxy=HttpProxyClient.Parse("127.0.0.1:8080");// Type: Socks4httpRequest.Proxy=Socks4ProxyClient.Parse("127.0.0.1:9000");// Type: Socks4ahttpRequest.Proxy=Socks4aProxyClient.Parse("127.0.0.1:9000");// Type: Socks5httpRequest.Proxy=Socks5ProxyClient.Parse("127.0.0.1:9000");Debug proxy server (Charles / Fiddler):
// HTTP / HTTPS (by default is HttpProxyClient at 127.0.0.1:8888)httpRequest.Proxy=ProxyClient.DebugHttpProxy;// Socks5 (by default is Socks5ProxyClient at 127.0.0.1:8889)httpRequest.Proxy=ProxyClient.DebugSocksProxy;request.Cookies.Set(stringname,stringvalue,stringdomain,stringpath="/");// orvarcookie=newCookie(stringname,stringvalue,stringdomain,stringpath);request.Cookies.Set(cookie);- Implement Captcha Services
- Move
HttpResponseindexer toHeadersproperty and implement IEnumerable for it - Implement new property
StoreResponseCookiesforHttpRequest:HttpResponseshould haveCookiesasIReadOnlyKeyValueCollection<string,Cookie>with indexer.