Fetch_dotNET 1.2.5

Install-Package Fetch_dotNET -Version 1.2.5
dotnet add package Fetch_dotNET --version 1.2.5
<PackageReference Include="Fetch_dotNET" Version="1.2.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Fetch_dotNET --version 1.2.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Fetch_dotNET, 1.2.5"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Fetch_dotNET as a Cake Addin
#addin nuget:?package=Fetch_dotNET&version=1.2.5

// Install Fetch_dotNET as a Cake Tool
#tool nuget:?package=Fetch_dotNET&version=1.2.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

class Program { static async Task Main(string[] args) { Console.WriteLine("Using Fetch");

	// method: 'IsConnectedToInternet'
	Console.WriteLine("> IsConnectedToInternet");
	bool isConnected = HttpClient.IsConnectedToInternet();
	if (!isConnected) return;
	Console.WriteLine("IsConnectedToInternet: " + isConnected);

	// method: 'GetLocalIP OR GetPublicIP'
	Console.WriteLine("> GetLocalIP OR GetPublicIP");
	string myLocalIP  = HttpClient.GetLocalIP();
	string myPublicIP = HttpClient.GetPublicIP();
	Console.WriteLine("My local IP Address is " + myLocalIP);
	Console.WriteLine("My public IP Address is " + myPublicIP);

	// method: 'GetMacAddress'
	Console.WriteLine("> GetMacAddress");
	string myMAC = HttpClient.GetMacAddress();
	Console.WriteLine("My MAC Address is " + myMAC);

	// method: 'PING'
	Console.WriteLine("> PING");
	string addressPing = "http://188.213.169.36";
	//string address = "http://localhost/api/Azienda?lic_id=5383";
	var httpPingResponse = HttpClient.PingHost(addressPing);
	Console.WriteLine("response:");
	Console.WriteLine(httpPingResponse);
	DisplayResponseStatus(httpPingResponse);


	// method: 'GET'
	Console.WriteLine("> GET");
	string address = "http://localhost/api/Azienda?lic_id=5383";
	var httpResponse = HttpClient.Fetch(address);
	Console.WriteLine("response:");
	Console.WriteLine(httpResponse);
	DisplayResponseStatus(httpResponse);
	
	// method: 'GET WITH TIMEOUT'
	Console.WriteLine("> GET WITH TIMEOUT");
	httpResponse = HttpClient.Fetch(address, 3000);
	//httpResponse = HttpClient.Fetch(address, "GET", "", "", 3000);
	Console.WriteLine("response:");
	Console.WriteLine(httpResponse);
	DisplayResponseStatus(httpResponse);

	// method: 'GET'
	Console.WriteLine("> GET ASYNC");
	address = "http://localhost/api/Azienda?lic_id=5383";
	//var httpResponseAsync = HttpClient.Fetch(address, "GET");
	//var httpResponseAsync = HttpClient.Fetch(address, "GET", null, null, true);
	var httpResponseAsync = await HttpClient.FetchAsync(address);
	Console.WriteLine("response:");
	Console.WriteLine(httpResponseAsync);
	DisplayResponseStatus(httpResponseAsync);


	// Set the User - Agent using the WebHeaderCollection:
	WebHeaderCollection headers = new WebHeaderCollection();
	// Add a user agent header in case the requested URI contains a query.
	headers[HttpRequestHeader.UserAgent] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";

	//string jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1N.iJ9-nAFFxkF2L85jj9lXf6alQV1pqiIqxOmQ";
	//// Adding authorization token to header
	//headers[HttpRequestHeader.Authorization] = "Bearer " + jwt;
	//// Resetting content type to be sent if we wanted to POST JSON
	//headers[HttpRequestHeader.ContentType] = "application/json; charset=utf-8";

	string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("369trWQC"+":"+"5t912es"));
	headers[HttpRequestHeader.Authorization] = "Basic " + credentials;

	// method: 'GET WITH BASICAUTH'
	Console.WriteLine("> GET WITH BASICAUTH");
	//var httpResponse = HttpClient.Fetch(address, headers);
	var httpResponseBasicAuth = HttpClient.Fetch(address, "GET", "", "", false, 3000, headers);
	Console.WriteLine("response:");
	Console.WriteLine(httpResponseBasicAuth);
	DisplayResponseStatus(httpResponseBasicAuth);

	// method: 'GET WITH TOKEN JWT'
	Console.WriteLine("> GET WITH TOKEN JWT");
	var httpResponseJWT = HttpClient.Fetch(address, headers);
	//var httpResponseJWT = HttpClient.Fetch(address, "GET", "", "", false, 3000, headers);
	Console.WriteLine("response:");
	Console.WriteLine(httpResponseJWT);
	DisplayResponseStatus(httpResponseJWT);
	
	// BASICAUTH
	var fetchOptions1 = "{" +
		"'method': 'GET'," +
		"'headers': {" +
			"'Accept': 'application/json'," +
			"'Content-Type': 'application/json'," +
			"'Authorization': 'Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes("369trWQC"+":"+"5t912es")) + "'" +
		"}," +
		"'timeout': 3000" +
	"}";

	// TOKEN JWT
	var fetchOptions2 = "{" +
		"'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" + // 3 second timeout
	"}";


	// method: 'GET WITH TOKEN JWT'
	Console.WriteLine("> GET WITH TOKEN JWT");
	var httpResponseJWT = await HttpClient.FetchAsync(address, fetchOptions2, data);
	Console.WriteLine("response:");
	Console.WriteLine(httpResponseJWT);
	DisplayResponseStatus(httpResponseJWT);


	// method: 'POST'
	Console.WriteLine("> POST");
	string addressPost = "http://localhost/api/Appuntamenti";
	string json = "{'shop_id':8000,'read':'secondary','events':[{'app_id':0,'eventType':'draft','eventColor':'lime'}]}";
	var httpResponsePost = HttpClient.Fetch(addressPost, "POST", json);
	Console.WriteLine("response:");
	Console.WriteLine(httpResponsePost);
	DisplayResponseStatus(httpResponsePost);
	
	// method: 'POST WITH TIMEOUT'
	Console.WriteLine("> POST WITH TIMEOUT");
	httpResponsePost = HttpClient.Fetch(addressPost, "POST", json, "", 3000);
	Console.WriteLine("response:");
	Console.WriteLine(httpResponsePost);
	DisplayResponseStatus(httpResponsePost);

	// method: 'POST'
	Console.WriteLine("> POST ASYNC");
	//var httpResponsePostAsync = HttpClient.Fetch(addressPost, "POST", json, null, true);
	var httpResponsePostAsync = await HttpClient.FetchAsync(addressPost, "POST", json);
	Console.WriteLine("response:");
	Console.WriteLine(httpResponsePostAsync);
	DisplayResponseStatus(httpResponsePostAsync);

	// method: 'POST'
	Console.WriteLine("> POST");
	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 httpResponsePost2 = HttpClient.Fetch(addressLog, values);
	//var httpResponsePost2 = HttpClient.Fetch(addressLog, "POST", values);
	//var httpResponsePost2 = HttpClient.Fetch(addressLog, "POST", values, true);
	Console.WriteLine("response:");
	Console.WriteLine(httpResponsePost2);
	DisplayResponseStatus(httpResponsePost2);


	// method: 'DOWNLOAD'
	Console.WriteLine("> DOWNLOAD ASYNC");
	string book = "http://localhost/books/Extjs-Release1.0.0.pdf";
	string fileName = @"C:\Users\matrix\Desktop\nuget_packages-SyncData\SyncData\Extjs-Release1.0.0.pdf";
	var httpResponseDownload = HttpClient.FetchDownloadFile(book, fileName);
	Console.WriteLine("response:");
	Console.WriteLine(httpResponseDownload);
	DisplayResponseStatus(httpResponseDownload);
}

private static void DisplayResponseStatus(HttpResponse httpResponse)
{
	// Write results
	Console.ForegroundColor = httpResponse.StatusCode == System.Net.HttpStatusCode.OK ? ConsoleColor.Green : ConsoleColor.Red;
	int statusCode = (int)httpResponse.StatusCode;
	Console.WriteLine("StatusCode: " + statusCode +" - "+ httpResponse.StatusCode);

	var tsEnded     = TimeSpan.FromTicks(httpResponse.CompleteTime.Ticks);
	var tsStarted   = TimeSpan.FromTicks(httpResponse.StartTime.Ticks);
	var durationTs  = tsEnded.Subtract(tsStarted);
	var durationstr = $"{durationTs.Hours}:{durationTs.Minutes}:{durationTs.Seconds}.{durationTs.Milliseconds}";

	var s = $"Total duration :{durationstr} ";

	Console.WriteLine(s);
	Console.ResetColor();
	Console.WriteLine(String.Empty);
}

}

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.2.5 100 7/25/2021
1.2.4 107 6/9/2021
1.2.3 130 3/22/2021
1.2.2 188 12/13/2020
1.2.1 228 10/24/2020
1.2.0 222 10/11/2020
1.1.1 179 8/12/2020
1.1.0 174 8/6/2020
1.0.9 264 8/6/2020
1.0.8 159 8/5/2020
1.0.7 160 8/4/2020
1.0.6 159 8/4/2020
1.0.5 221 8/3/2020
1.0.4 244 7/28/2020
1.0.3 171 7/28/2020
1.0.2 212 7/19/2020
1.0.1 173 7/19/2020
1.0.0 166 7/18/2020

Extensions on the Fetch .NetFramework.