Fetch_dotNET.Core 1.0.1

dotnet add package Fetch_dotNET.Core --version 1.0.1
                    
NuGet\Install-Package Fetch_dotNET.Core -Version 1.0.1
                    
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="Fetch_dotNET.Core" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fetch_dotNET.Core" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Fetch_dotNET.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Fetch_dotNET.Core --version 1.0.1
                    
#r "nuget: Fetch_dotNET.Core, 1.0.1"
                    
#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.
#:package Fetch_dotNET.Core@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Fetch_dotNET.Core&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Fetch_dotNET.Core&version=1.0.1
                    
Install as a Cake Tool

Fetch_dotNET.Core (Modern .NET)

Fetch_dotNET.Core è una libreria leggera di utility HTTP pensata per .NET moderno (net10.0).
Offre un wrapper ad alto livello su System.Net.Http.HttpClient con API sync/async, download file e utility di rete.

Nota: questa libreria espone una classe statica chiamata HttpClient (namespace Fetch_dotNET.Core).
Per evitare confusione con System.Net.Http.HttpClient, nel tuo codice puoi usare l’alias del namespace oppure il nome completo.


Requisiti

  • .NET 10.0
  • Dipendenze:
    • Newtonsoft.Json (per parsing di opzioni/headers in JSON)

Installazione

.NET CLI

dotnet add package Fetch_dotNET.Core

Package Manager

Install-Package Fetch_dotNET.Core

Panoramica delle funzionalità

  • GET / POST / PUT / DELETE (sync e async)
  • Timeout per richiesta
  • Headers personalizzati (User-Agent, Authorization, Content-Type, ecc.)
  • Supporto a:
    • Basic Auth
    • Bearer JWT
  • Invio dati:
    • stringa (tipicamente JSON)
    • NameValueCollection (form-url-encoded)
  • Download file
  • Utility: IP locale/pubblico, MAC address, ping, check URL, ecc.

Quick start

using System;
using System.Threading.Tasks;
using Fetch_dotNET.Core;

class Program
{
    static async Task Main()
    {
        // Verifica connessione
        if (!HttpClient.IsConnectedToInternet())
            return;

        // GET (sync)
        var r1 = HttpClient.Fetch("http://localhost/api/Azienda?lic_id=5383");
        Console.WriteLine(r1);

        // GET (async)
        var r2 = await HttpClient.FetchAsync("http://localhost/api/Azienda?lic_id=5383");
        Console.WriteLine(r2);
    }
}

Esempi completi

Gli esempi seguenti sono presi dal progetto di esempio e mostrano l’uso delle principali API.

1) Utility di rete

bool isConnected = HttpClient.IsConnectedToInternet();
string myLocalIP  = HttpClient.GetLocalIP();
string myPublicIP = HttpClient.GetPublicIP();
string myMAC      = HttpClient.GetMacAddress();

2) Ping

var httpPingResponse = HttpClient.PingHost("http://192.168.1.1");
Console.WriteLine(httpPingResponse);

3) GET con timeout

var httpResponse = HttpClient.Fetch("http://localhost/api/Azienda?lic_id=5383", 3000);
Console.WriteLine(httpResponse);

4) GET async

var httpResponseAsync = await HttpClient.FetchAsync("http://localhost/api/Azienda?lic_id=5383");
Console.WriteLine(httpResponseAsync);

5) GET con Basic Auth (headers)

using System.Net;
using System.Text;

WebHeaderCollection headers = new WebHeaderCollection();
headers[HttpRequestHeader.UserAgent] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";

string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("username:password"));
headers[HttpRequestHeader.Authorization] = "Basic " + credentials;

var resp = HttpClient.Fetch("http://localhost/api/Azienda?lic_id=5383", "GET", "", "", false, 3000, headers);
Console.WriteLine(resp);

6) GET con Bearer JWT (headers)

using System.Net;

WebHeaderCollection headers = new WebHeaderCollection();
headers[HttpRequestHeader.Authorization] = "Bearer " + jwt;

var resp = HttpClient.Fetch("http://localhost/api/Azienda?lic_id=5383", headers);
Console.WriteLine(resp);

7) GET con fetchOptions (JSON headers + timeout)

string fetchOptions = "{" +
    "'method': 'GET'," +
    "'headers': {" +
        "'Accept': 'application/json'," +
        "'Content-Type': 'application/json'," +
        "'Authorization': 'Bearer " + jwt + "'," +
        "'User-Agent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/6.0;)'" +
    "}," +
    "'timeout': 3000" +
"}";

var resp = await HttpClient.FetchAsync("http://localhost/api/Azienda?lic_id=5383", fetchOptions, data: null);
Console.WriteLine(resp);

8) POST JSON

string addressPost = "http://localhost/api/Appuntamenti";
string json = "{'shop_id':8000,'read':'secondary','events':[{'app_id':0,'eventType':'draft','eventColor':'lime'}]}";

var resp = HttpClient.Fetch(addressPost, "POST", json);
Console.WriteLine(resp);

9) POST con NameValueCollection (form)

using System.Collections.Specialized;

var values = new NameValueCollection();
values["product"] = "Fetch_dotNET";
values["version"] = "1.0.0";
values["log"]     = "13/06/20 18:51:03 ERROR ParseFormUPDATE";

string addressLog = "http://localhost/api/addLog.php";
var resp = HttpClient.Fetch(addressLog, values);
Console.WriteLine(resp);

10) Download file

string fileUrl  = "http://localhost/books/Extjs-Release1.0.0.pdf";
string fileName = @"C:\path\to\Extjs-Release1.0.0.pdf";

var resp = HttpClient.FetchDownloadFile(fileUrl, fileName);
Console.WriteLine(resp);

Note su timeout

Molti overload accettano timeout in millisecondi (es: 3000 = 3 secondi).


Licenza

Vedi la licenza del pacchetto su NuGet.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.1 119 1/17/2026
1.0.0 116 1/17/2026

HTTP client helper library for modern .NET