nanoFramework.System.Net.Http.Client 1.5.13 The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved

.NET Framework
Install-Package nanoFramework.System.Net.Http.Client -Version 1.5.13
dotnet add package nanoFramework.System.Net.Http.Client --version 1.5.13
<PackageReference Include="nanoFramework.System.Net.Http.Client" Version="1.5.13" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add nanoFramework.System.Net.Http.Client --version 1.5.13
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: nanoFramework.System.Net.Http.Client, 1.5.13"
#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 nanoFramework.System.Net.Http.Client as a Cake Addin
#addin nuget:?package=nanoFramework.System.Net.Http.Client&version=1.5.13

// Install nanoFramework.System.Net.Http.Client as a Cake Tool
#tool nuget:?package=nanoFramework.System.Net.Http.Client&version=1.5.13
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Quality Gate Status Reliability Rating License NuGet #yourfirstpr Discord

nanoFramework logo


Welcome to the .NET nanoFramework System.Net.Http Library repository

Build status

Component Build Status NuGet Package
System.Net.Http Build Status NuGet
System.Net.Http.Client Build Status NuGet
System.Net.Http.Server Build Status NuGet

Usage examples

The API, classes and namespaces in this library follow, as close as possible, the .NET ones. Exceptions are the lack of async calls, generics and the Task, async/await model. The names reflect that by dropping the Async suffix and not returning Task and the lack of the overloaded methods with CancelationToken parameters.

Also worth mentioning is the need to pass the CA root certificate to HttpClient in order to be able to validate the server certificate.

HttpClient calling REST services

HttpClient makes it very easy to connect and consume REST services. In order to use it, one has to create the object and them perform the calls. Note that HttpClient is meant to be reused throughout the application lifecycle. There is no need to create a new instance every time a call has to be performed. Like this:

static readonly HttpClient _httpClient = new HttpClient();

To pass the CA root certificate allowing to validate the secure server certificate. The CA root cert can also come from a binary file or text file from a resource.

_httpClient.HttpsAuthentCert = new X509Certificate(
@"-----BEGIN CERTIFICATE-----
MIIEDzCCAvegAw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JKtv3
L7IezMdeatiDh6GX70k1PncGQVhiv45YuApnP+yz3SFmH8lU+nLMPUxA2IGvd56D
eruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJl
xy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynp
VSJYACPq4xJDKVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEY
WQPJIrSPnNVeKtelttQKbfi3QBFGmh95DmK/D5fs4C8fF5Q=
-----END CERTIFICATE-----");

It's possible to add HTTP headers that will be sent along with each request.

_httpClient.DefaultRequestHeaders.Add("x-ms-blob-type", "BlockBlob");

Perform a HTTP GET request

Here's a example of a HTTP request to read some content as a string:

HttpResponseMessage response = _httpClient.Get("https://httpbin.org/get");
response.EnsureSuccessStatusCode();
var responseBody = response.Content.ReadAsString();

The above call would return something similar to the following, which can be output in Visual Studio by calling Debug.WriteLine(responseBody):

{
  "args": {}, 
  "headers": {
    "Host": "httpbin.org", 
    "X-Amzn-Trace-Id": "Root=1-6214aad3-38e5f8357bdf90530300eb5f", 
    "X-Ms-Blob-Type": "BlockBlob"
  }, 
  "origin": "5.249.47.208", 
  "url": "https://httpbin.org/get"
}

Note the call to response.EnsureSuccessStatusCode();. This will throw an HttpRequestException in case the status code from the HTTP request is not a successful one.

Perform a HTTP POST request

Follows an example of a HTTP request performing POST request to send some json content to an endpoint.

var content = new StringContent("{\"someProperty\":\"someValue\"}", Encoding.UTF8, "application/json");
var result = _httpClient.Post("https://httpbin.org/anything", content);
result.EnsureSuccessStatusCode();

Worth noting that the json content above it's presented as a simple string to simplify the code. There is a json library available to help with serializing and deserializing from/to C# classes, even the most complex ones.

Again, note the call to response.EnsureSuccessStatusCode(); to make sure the HTTP request was successfully performed.

Download binary content to a file

Using HttpClient makes it easy to deal with binary content too. Here's an example of how to download a file from a webserver.

HttpResponseMessage response = _httpClient.Get("https://storage-on-the-cloud.net/file-with-binary-content");
response.EnsureSuccessStatusCode();

using FileStream fs = new FileStream($"I:\\i-am-a-binary-file.bin", FileMode.Create, FileAccess.Write);
response.Content.ReadAsStream().CopyTo(fs);

Debugging through a reverse proxy

When code is deployed to a MCU it might be desirable to let the device connect to your development machine running IIS Express. This can be achieved with a proxy such as this one. Be aware that this leads to SocketExceptions with the current version of nanoFramework System.Net.Http when sending consecutive requests to your development machine. A simple retry mechanism in Debug mode will get around this.

Feedback and documentation

For documentation, providing feedback, issues and finding out how to contribute please refer to the Home repo.

Join our Discord community here.

Credits

The list of contributors to this project can be found at CONTRIBUTORS.

License

The nanoFramework Class Libraries are licensed under the MIT license.

Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behaviour in our community. For more information see the .NET Foundation Code of Conduct.

.NET Foundation

This project is supported by the .NET Foundation.

Product Versions
.NET Framework net
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on nanoFramework.System.Net.Http.Client:

Repository Stars
dotnet/samples
Sample code referenced by the .NET documentation
nanoframework/Samples
🍬 Code samples from the nanoFramework team used in testing, proof of concepts and other explorational endeavours
Version Downloads Last updated
1.5.13 51 8/5/2022
1.5.10 28 8/4/2022
1.5.8 27 8/4/2022
1.5.6 28 8/4/2022
1.5.4 34 8/3/2022
1.5.2 29 8/3/2022
1.4.0.25 32 8/3/2022
1.4.0.23 228 6/13/2022
1.4.0.21 79 6/8/2022
1.4.0.19 67 6/8/2022
1.4.0.14 109 5/26/2022
1.4.0.12 89 5/18/2022
1.4.0.10 109 5/3/2022
1.4.0 210 3/28/2022
1.4.0-preview.52 48 3/28/2022
1.4.0-preview.51 48 3/28/2022
1.4.0-preview.50 46 3/28/2022
1.4.0-preview.48 47 3/28/2022
1.4.0-preview.47 48 3/28/2022
1.4.0-preview.46 47 3/28/2022
1.4.0-preview.44 63 3/17/2022
1.4.0-preview.43 47 3/17/2022
1.4.0-preview.42 47 3/14/2022
1.4.0-preview.41 43 3/14/2022
1.4.0-preview.40 44 3/14/2022
1.4.0-preview.39 44 3/14/2022
1.4.0-preview.37 45 3/14/2022
1.4.0-preview.36 57 3/8/2022
1.4.0-preview.35 48 3/8/2022
1.4.0-preview.33 51 3/4/2022
1.4.0-preview.32 49 3/3/2022
1.4.0-preview.31 51 3/2/2022
1.4.0-preview.29 91 2/28/2022
1.4.0-preview.28 119 2/24/2022
1.4.0-preview.26 65 2/17/2022
1.4.0-preview.24 55 2/17/2022
1.4.0-preview.22 88 2/6/2022
1.4.0-preview.21 70 2/4/2022
1.4.0-preview.19 67 2/4/2022
1.4.0-preview.18 75 1/28/2022
1.4.0-preview.16 62 1/28/2022
1.4.0-preview.15 65 1/28/2022
1.4.0-preview.13 66 1/28/2022
1.4.0-preview.12 72 1/21/2022
1.4.0-preview.6 84 1/12/2022
1.4.0-preview.5 69 1/12/2022
1.4.0-preview.4 67 1/11/2022
1.4.0-preview.3 69 1/11/2022
1.3.7-preview.8 73 1/5/2022
1.3.7-preview.7 77 1/3/2022
1.3.7-preview.6 75 1/3/2022
1.3.7-preview.5 77 1/3/2022
1.3.7-preview.4 71 12/30/2021
1.3.7-preview.3 76 12/28/2021
1.3.6 358 12/3/2021
1.3.6-preview.23 79 12/3/2021
1.3.6-preview.21 76 12/3/2021
1.3.6-preview.20 79 12/2/2021
1.3.6-preview.19 82 12/2/2021
1.3.6-preview.18 77 12/2/2021
1.3.6-preview.17 75 12/2/2021
1.3.6-preview.16 77 12/2/2021
1.3.6-preview.14 79 12/2/2021
1.3.6-preview.12 79 12/2/2021
1.3.6-preview.10 78 12/1/2021
1.3.6-preview.7 83 12/1/2021
1.3.6-preview.1 143 11/11/2021
1.3.5-preview.8 82 10/22/2021
1.3.5-preview.5 101 10/18/2021
1.3.4 636 7/16/2021
1.3.4-preview.78 88 7/16/2021
1.3.4-preview.76 87 7/16/2021
1.3.4-preview.74 92 7/16/2021
1.3.4-preview.72 98 7/15/2021
1.3.4-preview.70 108 7/14/2021
1.3.4-preview.68 544 6/19/2021
1.3.4-preview.66 198 6/19/2021
1.3.4-preview.64 97 6/17/2021
1.3.4-preview.62 98 6/7/2021
1.3.4-preview.60 100 6/7/2021
1.3.4-preview.58 131 6/7/2021
1.3.4-preview.56 142 6/6/2021
1.3.4-preview.54 142 6/3/2021
1.3.4-preview.52 95 6/2/2021
1.3.4-preview.50 115 6/1/2021
1.3.4-preview.48 117 6/1/2021
1.3.4-preview.41 135 5/25/2021
1.3.4-preview.39 156 5/21/2021
1.3.4-preview.37 151 5/20/2021
1.3.4-preview.35 105 5/19/2021
1.3.4-preview.33 110 5/19/2021
1.3.4-preview.31 123 5/19/2021
1.3.4-preview.29 96 5/15/2021
1.3.4-preview.27 97 5/15/2021
1.3.4-preview.25 97 5/15/2021
1.3.4-preview.23 103 5/13/2021
1.3.4-preview.22 102 5/13/2021
1.3.4-preview.20 119 5/11/2021
1.3.4-preview.18 164 5/6/2021
1.3.4-preview.16 92 5/6/2021
1.3.4-preview.14 93 5/5/2021
1.3.4-preview.13 86 5/5/2021
1.3.4-preview.10 125 4/10/2021
1.3.4-preview.9 134 4/9/2021
1.3.4-preview.7 110 4/5/2021
1.3.3-preview.65 161 3/20/2021
1.3.3-preview.62 136 3/19/2021
1.3.3-preview.60 95 3/17/2021
1.3.3-preview.57 96 3/17/2021
1.3.3-preview.55 126 3/2/2021
1.3.3-preview.50 325 1/19/2021
1.3.3-preview.47 135 1/6/2021
1.3.3-preview.40 123 12/29/2020
1.3.3-preview.34 199 12/7/2020
1.3.3-preview.32 156 12/7/2020
1.3.3-preview.27 183 11/3/2020
1.3.3-preview.25 181 10/26/2020
1.3.3-preview.23 195 10/21/2020
1.3.3-preview.17 187 10/20/2020
1.3.3-preview.15 253 10/1/2020
1.3.3-preview.11 176 9/30/2020
1.3.3-preview.9 184 9/30/2020
1.3.3-preview.7 203 9/27/2020
1.3.3-preview.5 207 9/27/2020
1.3.3-preview.1 173 9/24/2020
1.3.2-preview.3 201 9/19/2020
1.3.2-preview.1 260 8/25/2020
1.3.1-preview.6 211 7/2/2020
1.3.1-preview.3 252 6/30/2020
1.3.0 362 6/16/2020
1.3.0-rc.3 222 6/16/2020
1.3.0-preview.11 233 6/16/2020
1.3.0-preview.9 177 6/16/2020
1.3.0-preview.7 177 6/16/2020
1.3.0-alpha.12 229 6/16/2020
1.3.0-alpha.10 175 6/16/2020
1.3.0-alpha.8 178 6/16/2020
1.2.2 261 6/12/2020
1.2.2-preview.41 175 6/12/2020
1.2.2-preview.39 194 6/12/2020
1.2.2-preview.34 190 6/3/2020
1.2.2-preview.33 201 6/3/2020
1.2.2-preview.31 293 5/31/2020
1.2.2-preview.30 188 5/31/2020
1.2.2-preview.29 216 5/31/2020
1.2.2-preview.28 201 5/29/2020
1.2.2-preview.27 213 5/8/2020
1.2.2-preview.26 207 5/8/2020
1.2.2-preview.25 188 4/27/2020
1.2.2-preview.24 184 4/24/2020
1.2.2-preview.23 179 4/21/2020
1.2.2-preview.22 220 4/16/2020
1.2.2-preview.19 213 4/16/2020
1.2.2-preview.18 190 4/14/2020
1.2.2-preview.17 188 4/14/2020
1.2.2-preview.16 188 4/14/2020
1.2.2-preview.15 229 3/25/2020
1.2.2-preview.14 234 3/15/2020
1.2.2-preview.13 187 3/10/2020
1.2.2-preview.12 186 3/10/2020
1.2.2-preview.10 183 3/10/2020
1.2.2-preview.8 189 3/10/2020
1.2.2-preview.7 191 3/10/2020
1.2.2-preview.6 210 3/9/2020
1.2.2-preview.5 211 3/9/2020
1.2.2-preview.4 192 3/6/2020
1.2.2-preview.3 235 1/13/2020
1.2.2-preview.2 249 11/14/2019
1.2.2-preview.1 201 11/12/2019
1.2.2-alpha.42 178 6/12/2020
1.2.2-alpha.40 196 6/12/2020
1.2.2-alpha.38 224 6/11/2020
1.2.2-alpha.35 183 6/3/2020
1.2.2-alpha.34 197 6/3/2020
1.2.2-alpha.32 293 5/31/2020
1.2.2-alpha.31 211 5/31/2020
1.2.2-alpha.30 218 5/30/2020
1.2.2-alpha.29 201 5/29/2020
1.2.2-alpha.28 205 5/8/2020
1.2.2-alpha.27 204 5/8/2020
1.2.2-alpha.26 183 4/27/2020
1.2.2-alpha.23 219 4/16/2020
1.2.2-alpha.21 210 4/16/2020
1.2.2-alpha.20 211 4/16/2020
1.2.2-alpha.19 186 4/14/2020
1.2.2-alpha.18 184 4/14/2020
1.2.2-alpha.17 183 4/14/2020
1.2.2-alpha.16 227 3/25/2020
1.2.2-alpha.15 232 3/15/2020
1.2.2-alpha.14 183 3/10/2020
1.2.2-alpha.13 178 3/10/2020
1.2.2-alpha.11 188 3/10/2020
1.2.2-alpha.10 184 3/10/2020
1.2.2-alpha.9 192 3/10/2020
1.2.2-alpha.8 212 3/9/2020
1.2.2-alpha.7 209 3/9/2020
1.2.2-alpha.6 219 3/9/2020
1.2.1-preview.3 200 11/8/2019
1.2.1-preview.1 210 11/5/2019
1.2.0-preview.3 202 10/18/2019
1.1.0 390 10/17/2019
1.1.0-preview.3 209 10/17/2019
1.0.8-preview.7 200 10/17/2019
1.0.8-preview.5 224 10/15/2019
1.0.8-preview.4 211 9/30/2019
1.0.8-preview.1 226 8/30/2019
1.0.7-preview.1 223 8/30/2019
1.0.6-preview.33 234 8/19/2019
1.0.6-preview.30 228 7/19/2019
1.0.6-preview.26 235 6/23/2019
1.0.6-preview.19 231 6/22/2019
1.0.6-preview.17 231 6/18/2019
1.0.5-preview-028 367 4/5/2019
1.0.5-preview-026 374 4/5/2019