MVNet 2.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MVNet --version 2.4.0                
NuGet\Install-Package MVNet -Version 2.4.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MVNet" Version="2.4.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MVNet --version 2.4.0                
#r "nuget: MVNet, 2.4.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MVNet as a Cake Addin
#addin nuget:?package=MVNet&version=2.4.0

// Install MVNet as a Cake Tool
#tool nuget:?package=MVNet&version=2.4.0                

MVNet Nuget

MVNet - provides HTTP/HTTPS, Socks 4A, Socks 4, Socks 5, Azadi.
It's a based on Leaf.xNet. And original library xNet.
Usage same like original xNet.

What has changed in this project?

MVNet

  • Supports TLS/SSL
  • Added Azadi Proxy
  • Fix Bugs

Features

HTTP Methods

  • GET
  • POST
  • PATCH
  • DELETE
  • PUT
  • OPTIONS

Keep temporary headers (when redirected)

It's enabled by default. But you can disable this behavior:

// After redirection to www.google.com - request won't have Referer header because KeepTemporaryHeadersOnRedirect = false
using (HttpRequest req = new HttpRequest("http://google.com"))
{
    req.KeepTemporaryHeadersOnRedirect = false;
    req.AddHeader(HttpHeader.Referer, "https://google.com");
    req.Get();
}

Middle response headers (when redirected)

using (HttpRequest req = new HttpRequest("https://account.sonyentertainmentnetwork.com/"))
{
    req.EnableMiddleHeaders = true;
    
    // This requrest has a lot of redirects
    var res = req.Get();
    var md = res.MiddleHeaders;
}

Cross Domain Cookies

Used native cookie storage from .NET with domain shared access support.
Cookies enabled by default. If you wait to disable parsing it use:

using (HttpRequest req = new HttpRequest("https://www.google.com/"))
{
    req.UseCookies = false;
}

Cookies now escaping values. If you wait to disable it use:

using (HttpRequest req = new HttpRequest("https://www.google.com/"))
{
    req.Cookies.EscapeValuesOnReceive = false;

    // UnescapeValuesOnSend by default = EscapeValuesOnReceive
    // so set if to false isn't necessary
    req.Cookies.UnescapeValuesOnSend = false;
}

Select SSL Protocols (downgrade when required)

using (HttpRequest req = new HttpRequest("https://www.google.com/"))
{
    // By Default (SSL 2 & 3 not used)
    req.SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13;
}

My HTTPS proxy returns bad response

Sometimes HTTPS proxy require relative address instead of absolute. This behavior can be changed:

using (HttpRequest req = new HttpRequest("https://www.google.com/"))
{
    req.Proxy.AbsoluteUriInStartingLine = false;
}

Cyrilic and Unicode Form parameters

var urlParams = new Parameters {
    { ["name"] = "value"  },
    { ["name"] = "value" }
}

// Or

var urlParams = new Parameters();
urlParams["name"] = "value";
urlParams["name"] = "value";

// Or

var urlParams = new Parameters();
urlParams.Add("name", "value");
urlParams.Add("name", "value");

using (HttpRequest req = new HttpRequest("https://www.google.com/"))
{
    string content = req.Get(urlParams).ReadAsString();
}

A lot of Substring functions

using (HttpRequest req = new HttpRequest("https://www.google.com/"))
{
    string content = req.Get().ReadAsString();
    
    string title = content.Substring("<title>", "</title>");

    // substring or default
    string titleWithDefault  = content.Substring("<title>", "</title>") ?? "Nothing";
    string titleWithDefault2 = content.Substring("<title>", "</title>", fallback: "Nothing");

    // substring or empty
    string titleOrEmpty  = content.SubstringOrEmpty("<title>", "</title>");
    string titleOrEmpty2 = content.Substring("<title>", "</title>") ?? ""; // "" or string.Empty
    string titleOrEmpty3 = content.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 message
    string titleOrException  = content.SubstringEx("<title>", "</title>");

    // when you need your own Exception
    string titleOrException2 = content.Substring("<title>", "</title>") ?? throw MyCustomException();
}

How to:

Get started

Add in the beggining of file.

using MVNet;

And use one of this code templates:

using (var request = new HttpRequest("https://www.google.com/")) {
    // Do something
}

// Or
HttpRequest request = null;
try {
    request = new HttpRequest("https://www.google.com/");
    // Do something 
}
catch (HttpException ex) {
    // Http error handling
    // You can use ex.Status or ex.HttpStatusCode for more details.
}
catch (Exception ex) {
	// Unhandled exceptions
}
finally {
    // Cleanup in the end if initialized
    request?.Dispose();
}

Send multipart requests with fields and files

Methods AddField() and AddFile() has been removed (unstable). Use this code:

var multipartContent = new MultipartContent()
{
    {new StringContent("Harry Potter"), "login"},
    {new StringContent("Crucio"), "password"},
    {new FileContent(@"C:\hp.rar"), "file1", "hp.rar"}
};

// When response isn't required
using (HttpRequest req = new HttpRequest("https://www.google.com/"))
{
    req.Post(multipartContent);
}

// Or

using (HttpRequest req = new HttpRequest("https://www.google.com/"))
{
    var res = request.Post(multipartContent);
    // And then read as string
    string content = res.ReadAsString();
}

Get page source (response body) and find a value between strings

using (HttpRequest req = new HttpRequest("https://www.google.com/"))
{
    string content = request.Get().ReadAsString();
    string title = content.Substring("<title>", "</title>");
}

Get response headers

using (HttpRequest req = new HttpRequest("https://www.google.com/"))
{
    var res = req.Get();
    
    string HeaderValue = res["name"];
    // Or
    string HeaderValue = res.GetHeader("name");
}

Download a file

using (HttpRequest req = new HttpRequest("http://google.com/file.zip"))
{
    var res = req.Get();
    res.Write("C:\\myDownloadedFile.zip");
}

Set Cookies

using (HttpRequest req = new HttpRequest("https://www.google.com/"))
{
    req.AddCookie("name", "value");
}

Get Cookies

using (HttpRequest req = new HttpRequest("https://www.google.com/"))
{
    var res = req.Get();
    string CookieValue = res.GetCookie("name");
}

Proxy

Your proxy server:

using (HttpRequest req = new HttpRequest("https://www.google.com/"))
{
    // Type: HTTP/HTTPS
    req.Proxy = HttpProxyClient.Parse("127.0.0.1:8080");

    // Type: Socks4
    req.Proxy = Socks4ProxyClient.Parse("127.0.0.1:9000");

    // Type: Socks4a
    req.Proxy = Socks4aProxyClient.Parse("127.0.0.1:9000");

    // Type: Socks5
    req.Proxy = Socks5ProxyClient.Parse("127.0.0.1:9000");

    // Type: Azadi
    req.Proxy = AzadiProxyClient.Parse("ap://AwAAAAkxMjcuMC4wLjEEOTg5OAZzZWNyZXQ%3d");
    // or
    req.Proxy = AzadiProxyClient.Parse("127.0.0.1:9898:secret");
    // or
    req.Proxy = AzadiProxyClient.Parse("127.0.0.1:9898:username:password:secret");
}

Debug proxy server (Charles / Fiddler):

using (HttpRequest req = new HttpRequest("https://www.google.com/"))
{
    // HTTP/HTTPS (by default is HttpProxyClient at 127.0.0.1:8888)
    req.Proxy = ProxyClient.DebugHttpProxy;

    // Socks5 (by default is Socks5ProxyClient at 127.0.0.1:8889)
    req.Proxy = ProxyClient.DebugSocksProxy;
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 226 8/4/2023
2.4.0 179 7/24/2023
2.3.0 184 4/8/2023
2.2.0 337 12/5/2022
2.1.0 351 11/2/2022