Advanced Network Client
The AdvancedNetworkClient
class is a modified version of the HttpClient
class that provides additional features for network operations in .NET 6.0+. This class extends the functionality of HttpClient
to simplify common networking tasks such as downloading files, uploading files, and making HTTP requests that return JSON data.
Class Overview
Namespace
Inheritance
Inherits from:
HttpClient
License
This class is licensed under the GNU General Public License (GPL-3.0). For more details, refer to GPL-3.0 License.
Methods
DownloadFileAsync
Description: Downloads a file from the specified URI and saves it to the given file path.
Parameters:
address
(Uri): The direct download URI of the file.path
(string): The directory or absolute file path where the downloaded file will be saved.progress
(DownloadProgressEvent?): An optional event handler for tracking the download progress.
Returns:
A task that represents the asynchronous operation and returns the path of the downloaded file.
UploadFileAsync
Description: Uploads a file to the specified URI using an HTTP POST request.
Parameters:
address
(string): The destination URI where the file will be uploaded.file
(string): The path of the file to be uploaded.progress
(DownloadProgressEvent?): An optional event handler for tracking the upload progress.
Returns:
A task that represents the asynchronous operation and returns the HTTP response message.
GetAsJson
Description: Sends an HTTP request using the provided
HttpRequestMessage
and parses the response content as a JSON object (JObject).Parameters:
requestMessage
(HttpRequestMessage): The HTTP request message to send.
Returns:
A task that represents the asynchronous operation and returns a JObject representing the parsed JSON response, or null if the response is null.
GetAsJsonArray
Description: Sends an HTTP request using the provided
HttpRequestMessage
and parses the response content as a JSON array (JArray).Parameters:
requestMessage
(HttpRequestMessage): The HTTP request message to send.
Returns:
A task that represents the asynchronous operation and returns a JArray representing the parsed JSON response, or null if the response is null.
Example Usage
Here are some example usages of the AdvancedNetworkClient
class:
These examples demonstrate how to use the AdvancedNetworkClient
class to perform various networking tasks, including file downloads, uploads, and handling JSON responses. The optional progress event handlers allow you to track the progress of file transfers.
Last updated
Was this helpful?