nanoFramework.System.Net.Http.Client 1.5.27

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package nanoFramework.System.Net.Http.Client --version 1.5.27
                    
NuGet\Install-Package nanoFramework.System.Net.Http.Client -Version 1.5.27
                    
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="nanoFramework.System.Net.Http.Client" Version="1.5.27" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nanoFramework.System.Net.Http.Client" Version="1.5.27" />
                    
Directory.Packages.props
<PackageReference Include="nanoFramework.System.Net.Http.Client" />
                    
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 nanoFramework.System.Net.Http.Client --version 1.5.27
                    
#r "nuget: nanoFramework.System.Net.Http.Client, 1.5.27"
                    
#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 nanoFramework.System.Net.Http.Client@1.5.27
                    
#: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=nanoFramework.System.Net.Http.Client&version=1.5.27
                    
Install as a Cake Addin
#tool nuget:?package=nanoFramework.System.Net.Http.Client&version=1.5.27
                    
Install as a Cake Tool

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-----
MIIEDzCCAvegAwIBAgIBADANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJVUzEl
MCMGA1UEChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMp
U3RhcmZpZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDQw
NjI5MTczOTE2WhcNMzQwNjI5MTczOTE2WjBoMQswCQYDVQQGEwJVUzElMCMGA1UE
ChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMpU3RhcmZp
ZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEgMA0GCSqGSIb3
DQEBAQUAA4IBDQAwggEIAoIBAQC3Msj+6XGmBIWtDBFk385N78gDGIc/oav7PKaf
8MOh2tTYbitTkPskpD6E8J7oX+zlJ0T1KKY/e97gKvDIr1MvnsoFAZMej2YcOadN
+lq2cwQlZut3f+dZxkqZJRRU6ybH838Z1TBwj6+wRir/resp7defqgSHo9T5iaU0
X9tDkYI22WY8sbi5gv2cOj4QyDvvBmVmepsZGD3/cVE8MC5fvj13c7JdBmzDI1aa
K4UmkhynArPkPw2vCHmCuDY96pzTNbO8acr1zJ3o/WSNF4Azbl5KXZnJHoe0nRrA
1W4TNSNe35tfPe/W93bC6j67eA0cQmdrBNj41tpvi/JEoAGrAgEDo4HFMIHCMB0G
A1UdDgQWBBS/X7fRzt0fhvRbVazc1xDCDqmI5zCBkgYDVR0jBIGKMIGHgBS/X7fR
zt0fhvRbVazc1xDCDqmI56FspGowaDELMAkGA1UEBhMCVVMxJTAjBgNVBAoTHFN0
YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAsTKVN0YXJmaWVsZCBD
bGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8w
DQYJKoZIhvcNAQEFBQADggEBAAWdP4id0ckaVaGsafPzWdqbAYcaT1epoXkJKtv3
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 Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
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 (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.196 428 6/2/2025
1.5.195 273 4/24/2025
1.5.193 281 4/2/2025
1.5.192 517 3/26/2025
1.5.191 517 3/26/2025
1.5.189 226 3/10/2025
1.5.188 217 3/10/2025
1.5.187 212 3/10/2025
1.5.186 213 3/10/2025
1.5.184 173 3/3/2025
1.5.183 187 2/27/2025
1.5.182 129 2/27/2025
1.5.181 137 2/25/2025
1.5.180 144 2/25/2025
1.5.179 151 2/25/2025
1.5.178 134 2/25/2025
1.5.177 144 2/25/2025
1.5.175 215 2/5/2025
1.5.172 177 1/30/2025
1.5.171 132 1/30/2025
1.5.170 152 1/30/2025
1.5.169 144 1/30/2025
1.5.165 145 1/27/2025
1.5.162 227 1/6/2025
1.5.161 131 1/6/2025
1.5.159 139 1/6/2025
1.5.158 132 1/6/2025
1.5.157 163 1/2/2025
1.5.150 560 9/26/2024
1.5.145 263 7/30/2024
1.5.138 353 5/13/2024
1.5.136 253 5/10/2024
1.5.134 254 4/8/2024
1.5.132 151 4/8/2024
1.5.130 207 4/3/2024
1.5.128 156 4/3/2024
1.5.125 358 1/29/2024
1.5.118 179 1/24/2024
1.5.113 464 11/10/2023
1.5.110 171 11/9/2023
1.5.108 210 11/9/2023
1.5.106 202 11/3/2023
1.5.104 320 10/10/2023
1.5.102 255 10/4/2023
1.5.99 403 8/8/2023
1.5.97 360 7/27/2023
1.5.95 223 7/27/2023
1.5.84 709 2/17/2023
1.5.82 467 1/24/2023
1.5.78 464 12/28/2022
1.5.75 400 12/28/2022
1.5.73 424 12/28/2022
1.5.70 401 12/27/2022
1.5.68 435 12/22/2022
1.5.61 622 11/23/2022
1.5.54 590 10/26/2022
1.5.52 460 10/26/2022
1.5.50 520 10/26/2022
1.5.48 491 10/25/2022
1.5.45 507 10/25/2022
1.5.43 514 10/24/2022
1.5.41 537 10/24/2022
1.5.39 506 10/24/2022
1.5.37 508 10/23/2022
1.5.35 511 10/23/2022
1.5.30 542 10/10/2022
1.5.27 479 10/8/2022
1.5.24 569 9/22/2022
1.5.22 540 9/22/2022
1.5.20 635 9/15/2022
1.5.18 541 9/15/2022
1.5.13 760 8/5/2022
1.5.10 505 8/4/2022
1.5.8 524 8/4/2022
1.5.6 547 8/4/2022
1.5.4 537 8/3/2022
1.5.2 557 8/3/2022
1.4.0.25 551 8/3/2022
1.4.0.23 726 6/13/2022
1.4.0.21 543 6/8/2022
1.4.0.19 549 6/8/2022
1.4.0.14 603 5/26/2022
1.4.0.12 582 5/18/2022
1.4.0.10 606 5/3/2022
1.4.0 701 3/28/2022
1.4.0-preview.52 226 3/28/2022
1.4.0-preview.51 214 3/28/2022
1.4.0-preview.50 226 3/28/2022
1.4.0-preview.48 233 3/28/2022
1.4.0-preview.47 226 3/28/2022
1.4.0-preview.46 216 3/28/2022
1.4.0-preview.44 256 3/17/2022
1.4.0-preview.43 223 3/17/2022
1.4.0-preview.42 250 3/14/2022
1.4.0-preview.41 221 3/14/2022
1.4.0-preview.40 228 3/14/2022
1.4.0-preview.39 230 3/14/2022
1.4.0-preview.37 219 3/14/2022
1.4.0-preview.36 230 3/8/2022
1.4.0-preview.35 237 3/8/2022
1.4.0-preview.33 228 3/4/2022
1.4.0-preview.32 232 3/3/2022
1.4.0-preview.31 220 3/2/2022
1.4.0-preview.29 259 2/28/2022
1.4.0-preview.28 295 2/24/2022
1.4.0-preview.26 263 2/17/2022
1.4.0-preview.24 223 2/17/2022
1.4.0-preview.22 265 2/6/2022
1.4.0-preview.21 259 2/4/2022
1.4.0-preview.19 255 2/4/2022
1.4.0-preview.18 241 1/28/2022
1.4.0-preview.16 237 1/28/2022
1.4.0-preview.15 241 1/28/2022
1.4.0-preview.13 253 1/28/2022
1.4.0-preview.12 246 1/21/2022
1.4.0-preview.6 250 1/12/2022
1.4.0-preview.5 250 1/12/2022
1.4.0-preview.4 251 1/11/2022
1.4.0-preview.3 244 1/11/2022
1.3.7-preview.8 251 1/5/2022
1.3.7-preview.7 250 1/3/2022
1.3.7-preview.6 255 1/3/2022
1.3.7-preview.5 243 1/3/2022
1.3.7-preview.4 237 12/30/2021
1.3.7-preview.3 259 12/28/2021
1.3.6 671 12/3/2021
1.3.6-preview.23 253 12/3/2021
1.3.6-preview.21 255 12/3/2021
1.3.6-preview.20 246 12/2/2021
1.3.6-preview.19 257 12/2/2021
1.3.6-preview.18 259 12/2/2021
1.3.6-preview.17 250 12/2/2021
1.3.6-preview.16 268 12/2/2021
1.3.6-preview.14 266 12/2/2021
1.3.6-preview.12 242 12/2/2021
1.3.6-preview.10 258 12/1/2021
1.3.6-preview.7 252 12/1/2021
1.3.6-preview.1 320 11/11/2021
1.3.5-preview.8 257 10/22/2021
1.3.5-preview.5 271 10/18/2021
1.3.4 1,250 7/16/2021
1.3.4-preview.78 272 7/16/2021
1.3.4-preview.76 259 7/16/2021
1.3.4-preview.74 261 7/16/2021
1.3.4-preview.72 274 7/15/2021
1.3.4-preview.70 285 7/14/2021
1.3.4-preview.68 721 6/19/2021
1.3.4-preview.66 363 6/19/2021
1.3.4-preview.64 263 6/17/2021
1.3.4-preview.62 289 6/7/2021
1.3.4-preview.60 269 6/7/2021
1.3.4-preview.58 316 6/7/2021
1.3.4-preview.56 307 6/6/2021
1.3.4-preview.54 307 6/3/2021
1.3.4-preview.52 282 6/2/2021
1.3.4-preview.50 287 6/1/2021
1.3.4-preview.48 286 6/1/2021
1.3.4-preview.41 310 5/25/2021
1.3.4-preview.39 335 5/21/2021
1.3.4-preview.37 345 5/20/2021
1.3.4-preview.35 287 5/19/2021
1.3.4-preview.33 270 5/19/2021
1.3.4-preview.31 292 5/19/2021
1.3.4-preview.29 285 5/15/2021
1.3.4-preview.27 283 5/15/2021
1.3.4-preview.25 289 5/15/2021
1.3.4-preview.23 275 5/13/2021
1.3.4-preview.22 282 5/13/2021
1.3.4-preview.20 309 5/11/2021
1.3.4-preview.18 335 5/6/2021
1.3.4-preview.16 275 5/6/2021
1.3.4-preview.14 283 5/5/2021
1.3.4-preview.13 260 5/5/2021
1.3.4-preview.10 314 4/10/2021
1.3.4-preview.9 316 4/9/2021
1.3.4-preview.7 279 4/5/2021
1.3.3-preview.65 334 3/20/2021
1.3.3-preview.62 312 3/19/2021
1.3.3-preview.60 286 3/17/2021
1.3.3-preview.57 279 3/17/2021
1.3.3-preview.55 289 3/2/2021
1.3.3-preview.50 511 1/19/2021
1.3.3-preview.47 293 1/6/2021
1.3.3-preview.40 311 12/29/2020
1.3.3-preview.34 365 12/7/2020
1.3.3-preview.32 326 12/7/2020
1.3.3-preview.27 350 11/3/2020
1.3.3-preview.25 356 10/26/2020
1.3.3-preview.23 383 10/21/2020
1.3.3-preview.17 369 10/20/2020
1.3.3-preview.15 438 10/1/2020
1.3.3-preview.11 363 9/30/2020
1.3.3-preview.9 352 9/30/2020
1.3.3-preview.7 372 9/27/2020
1.3.3-preview.5 393 9/27/2020
1.3.3-preview.1 367 9/24/2020
1.3.2-preview.3 374 9/19/2020
1.3.2-preview.1 451 8/25/2020
1.3.1-preview.6 407 7/2/2020
1.3.1-preview.3 444 6/30/2020
1.3.0 672 6/16/2020
1.3.0-rc.3 406 6/16/2020
1.3.0-preview.11 432 6/16/2020
1.3.0-preview.9 346 6/16/2020
1.3.0-preview.7 371 6/16/2020
1.3.0-alpha.12 433 6/16/2020
1.3.0-alpha.10 340 6/16/2020
1.3.0-alpha.8 364 6/16/2020
1.2.2 582 6/12/2020
1.2.2-preview.41 361 6/12/2020
1.2.2-preview.39 363 6/12/2020
1.2.2-preview.34 379 6/3/2020
1.2.2-preview.33 387 6/3/2020
1.2.2-preview.31 478 5/31/2020
1.2.2-preview.30 359 5/31/2020
1.2.2-preview.29 402 5/31/2020
1.2.2-preview.28 385 5/29/2020
1.2.2-preview.27 392 5/8/2020
1.2.2-preview.26 386 5/8/2020
1.2.2-preview.25 370 4/27/2020
1.2.2-preview.24 381 4/24/2020
1.2.2-preview.23 356 4/21/2020
1.2.2-preview.22 417 4/16/2020
1.2.2-preview.19 396 4/16/2020
1.2.2-preview.18 374 4/14/2020
1.2.2-preview.17 367 4/14/2020
1.2.2-preview.16 392 4/14/2020
1.2.2-preview.15 399 3/25/2020
1.2.2-preview.14 418 3/15/2020
1.2.2-preview.13 454 3/10/2020
1.2.2-preview.12 379 3/10/2020
1.2.2-preview.10 368 3/10/2020
1.2.2-preview.8 386 3/10/2020
1.2.2-preview.7 367 3/10/2020
1.2.2-preview.6 408 3/9/2020
1.2.2-preview.5 406 3/9/2020
1.2.2-preview.4 385 3/6/2020
1.2.2-preview.3 433 1/13/2020
1.2.2-preview.2 448 11/14/2019
1.2.2-preview.1 382 11/12/2019
1.2.2-alpha.42 362 6/12/2020
1.2.2-alpha.40 373 6/12/2020
1.2.2-alpha.38 401 6/11/2020
1.2.2-alpha.35 378 6/3/2020
1.2.2-alpha.34 374 6/3/2020
1.2.2-alpha.32 471 5/31/2020
1.2.2-alpha.31 401 5/31/2020
1.2.2-alpha.30 390 5/30/2020
1.2.2-alpha.29 391 5/29/2020
1.2.2-alpha.28 408 5/8/2020
1.2.2-alpha.27 377 5/8/2020
1.2.2-alpha.26 382 4/27/2020
1.2.2-alpha.23 414 4/16/2020
1.2.2-alpha.21 386 4/16/2020
1.2.2-alpha.20 386 4/16/2020
1.2.2-alpha.19 363 4/14/2020
1.2.2-alpha.18 369 4/14/2020
1.2.2-alpha.17 383 4/14/2020
1.2.2-alpha.16 405 3/25/2020
1.2.2-alpha.15 410 3/15/2020
1.2.2-alpha.14 364 3/10/2020
1.2.2-alpha.13 355 3/10/2020
1.2.2-alpha.11 361 3/10/2020
1.2.2-alpha.10 370 3/10/2020
1.2.2-alpha.9 391 3/10/2020
1.2.2-alpha.8 396 3/9/2020
1.2.2-alpha.7 394 3/9/2020
1.2.2-alpha.6 404 3/9/2020
1.2.1-preview.3 383 11/8/2019
1.2.1-preview.1 388 11/5/2019
1.2.0-preview.3 396 10/18/2019
1.1.0 738 10/17/2019
1.1.0-preview.3 405 10/17/2019
1.0.8-preview.7 403 10/17/2019
1.0.8-preview.5 418 10/15/2019
1.0.8-preview.4 394 9/30/2019
1.0.8-preview.1 424 8/30/2019
1.0.7-preview.1 422 8/30/2019
1.0.6-preview.33 423 8/19/2019
1.0.6-preview.30 408 7/19/2019
1.0.6-preview.26 423 6/23/2019
1.0.6-preview.19 441 6/22/2019
1.0.6-preview.17 438 6/18/2019
1.0.5-preview-028 640 4/5/2019
1.0.5-preview-026 632 4/5/2019