nanoFramework.System.Net.Http.Client 1.4.0-preview.44

Prefix Reserved
This is a prerelease version of nanoFramework.System.Net.Http.Client.
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.4.0-preview.44
                    
NuGet\Install-Package nanoFramework.System.Net.Http.Client -Version 1.4.0-preview.44
                    
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.4.0-preview.44" />
                    
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.4.0-preview.44" />
                    
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.4.0-preview.44
                    
#r "nuget: nanoFramework.System.Net.Http.Client, 1.4.0-preview.44"
                    
#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.4.0-preview.44
                    
#: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.4.0-preview.44&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=nanoFramework.System.Net.Http.Client&version=1.4.0-preview.44&prerelease
                    
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 (preview) Build Status NuGet
System.Net.Http.Client Build Status NuGet
System.Net.Http.Client (preview) Build Status NuGet
System.Net.Http.Server Build Status NuGet
System.Net.Http.Server (preview) 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.200 529 11/19/2025
1.5.199 322 11/13/2025
1.5.196 624 6/2/2025
1.5.195 321 4/24/2025
1.5.193 329 4/2/2025
1.5.192 556 3/26/2025
1.5.191 568 3/26/2025
1.5.189 263 3/10/2025
1.5.188 266 3/10/2025
1.5.187 255 3/10/2025
1.5.186 264 3/10/2025
1.5.184 210 3/3/2025
1.5.183 237 2/27/2025
1.5.182 165 2/27/2025
1.5.181 182 2/25/2025
1.5.180 186 2/25/2025
1.5.179 196 2/25/2025
1.5.178 179 2/25/2025
1.5.177 191 2/25/2025
1.5.175 271 2/5/2025
1.5.172 215 1/30/2025
1.5.171 172 1/30/2025
1.5.170 198 1/30/2025
1.5.169 192 1/30/2025
1.5.165 193 1/27/2025
1.5.162 279 1/6/2025
1.5.161 168 1/6/2025
1.5.159 176 1/6/2025
1.5.158 178 1/6/2025
1.5.157 214 1/2/2025
1.5.150 592 9/26/2024
1.5.145 294 7/30/2024
1.5.138 397 5/13/2024
1.5.136 292 5/10/2024
1.5.134 291 4/8/2024
1.5.132 187 4/8/2024
1.5.130 247 4/3/2024
1.5.128 191 4/3/2024
1.5.125 395 1/29/2024
1.5.118 219 1/24/2024
1.5.113 513 11/10/2023
1.5.110 199 11/9/2023
1.5.108 255 11/9/2023
1.5.106 228 11/3/2023
1.5.104 361 10/10/2023
1.5.102 296 10/4/2023
1.5.99 436 8/8/2023
1.5.97 400 7/27/2023
1.5.95 268 7/27/2023
1.5.84 763 2/17/2023
1.5.82 515 1/24/2023
1.5.78 519 12/28/2022
1.5.75 439 12/28/2022
1.5.73 477 12/28/2022
1.5.70 448 12/27/2022
1.5.68 488 12/22/2022
1.5.61 670 11/23/2022
1.5.54 641 10/26/2022
1.5.52 520 10/26/2022
1.5.50 579 10/26/2022
1.5.48 536 10/25/2022
1.5.45 562 10/25/2022
1.5.43 562 10/24/2022
1.5.41 598 10/24/2022
1.5.39 561 10/24/2022
1.5.37 558 10/23/2022
1.5.35 567 10/23/2022
1.5.30 598 10/10/2022
1.5.27 531 10/8/2022
1.5.24 616 9/22/2022
1.5.22 595 9/22/2022
1.5.20 684 9/15/2022
1.5.18 587 9/15/2022
1.5.13 816 8/5/2022
1.5.10 562 8/4/2022
1.5.8 578 8/4/2022
1.5.6 602 8/4/2022
1.5.4 590 8/3/2022
1.5.2 622 8/3/2022
1.4.0.25 597 8/3/2022
1.4.0.23 783 6/13/2022
1.4.0.21 593 6/8/2022
1.4.0.19 600 6/8/2022
1.4.0.14 651 5/26/2022
1.4.0.12 636 5/18/2022
1.4.0.10 659 5/3/2022
1.4.0 753 3/28/2022
1.4.0-preview.52 275 3/28/2022
1.4.0-preview.51 260 3/28/2022
1.4.0-preview.50 277 3/28/2022
1.4.0-preview.48 288 3/28/2022
1.4.0-preview.47 275 3/28/2022
1.4.0-preview.46 254 3/28/2022
1.4.0-preview.44 301 3/17/2022
1.4.0-preview.43 260 3/17/2022
1.4.0-preview.42 291 3/14/2022
1.4.0-preview.41 266 3/14/2022
1.4.0-preview.40 281 3/14/2022
1.4.0-preview.39 286 3/14/2022
1.4.0-preview.37 258 3/14/2022
1.4.0-preview.36 273 3/8/2022
1.4.0-preview.35 289 3/8/2022
1.4.0-preview.33 272 3/4/2022
1.4.0-preview.32 283 3/3/2022
1.4.0-preview.31 268 3/2/2022
1.4.0-preview.29 304 2/28/2022
1.4.0-preview.28 338 2/24/2022
1.4.0-preview.26 324 2/17/2022
1.4.0-preview.24 270 2/17/2022
1.4.0-preview.22 310 2/6/2022
1.4.0-preview.21 311 2/4/2022
1.4.0-preview.19 309 2/4/2022
1.4.0-preview.18 282 1/28/2022
1.4.0-preview.16 283 1/28/2022
1.4.0-preview.15 286 1/28/2022
1.4.0-preview.13 310 1/28/2022
1.4.0-preview.12 301 1/21/2022
1.4.0-preview.6 301 1/12/2022
1.4.0-preview.5 305 1/12/2022
1.4.0-preview.4 307 1/11/2022
1.4.0-preview.3 299 1/11/2022
1.3.7-preview.8 306 1/5/2022
1.3.7-preview.7 294 1/3/2022
1.3.7-preview.6 310 1/3/2022
1.3.7-preview.5 288 1/3/2022
1.3.7-preview.4 275 12/30/2021
1.3.7-preview.3 307 12/28/2021
1.3.6 726 12/3/2021
1.3.6-preview.23 309 12/3/2021
1.3.6-preview.21 309 12/3/2021
1.3.6-preview.20 293 12/2/2021
1.3.6-preview.19 304 12/2/2021
1.3.6-preview.18 311 12/2/2021
1.3.6-preview.17 292 12/2/2021
1.3.6-preview.16 317 12/2/2021
1.3.6-preview.14 322 12/2/2021
1.3.6-preview.12 291 12/2/2021
1.3.6-preview.10 316 12/1/2021
1.3.6-preview.7 296 12/1/2021
1.3.6-preview.1 365 11/11/2021
1.3.5-preview.8 303 10/22/2021
1.3.5-preview.5 319 10/18/2021
1.3.4 1,331 7/16/2021
1.3.4-preview.78 324 7/16/2021
1.3.4-preview.76 302 7/16/2021
1.3.4-preview.74 304 7/16/2021
1.3.4-preview.72 317 7/15/2021
1.3.4-preview.70 334 7/14/2021
1.3.4-preview.68 769 6/19/2021
1.3.4-preview.66 405 6/19/2021
1.3.4-preview.64 303 6/17/2021
1.3.4-preview.62 352 6/7/2021
1.3.4-preview.60 313 6/7/2021
1.3.4-preview.58 367 6/7/2021
1.3.4-preview.56 354 6/6/2021
1.3.4-preview.54 352 6/3/2021
1.3.4-preview.52 343 6/2/2021
1.3.4-preview.50 344 6/1/2021
1.3.4-preview.48 329 6/1/2021
1.3.4-preview.41 369 5/25/2021
1.3.4-preview.39 384 5/21/2021
1.3.4-preview.37 398 5/20/2021
1.3.4-preview.35 339 5/19/2021
1.3.4-preview.33 316 5/19/2021
1.3.4-preview.31 338 5/19/2021
1.3.4-preview.29 343 5/15/2021
1.3.4-preview.27 337 5/15/2021
1.3.4-preview.25 342 5/15/2021
1.3.4-preview.23 312 5/13/2021
1.3.4-preview.22 327 5/13/2021
1.3.4-preview.20 356 5/11/2021
1.3.4-preview.18 382 5/6/2021
1.3.4-preview.16 317 5/6/2021
1.3.4-preview.14 333 5/5/2021
1.3.4-preview.13 311 5/5/2021
1.3.4-preview.10 365 4/10/2021
1.3.4-preview.9 377 4/9/2021
1.3.4-preview.7 323 4/5/2021
1.3.3-preview.65 388 3/20/2021
1.3.3-preview.62 366 3/19/2021
1.3.3-preview.60 344 3/17/2021
1.3.3-preview.57 340 3/17/2021
1.3.3-preview.55 335 3/2/2021
1.3.3-preview.50 565 1/19/2021
1.3.3-preview.47 341 1/6/2021
1.3.3-preview.40 369 12/29/2020
1.3.3-preview.34 426 12/7/2020
1.3.3-preview.32 378 12/7/2020
1.3.3-preview.27 403 11/3/2020
1.3.3-preview.25 409 10/26/2020
1.3.3-preview.23 440 10/21/2020
1.3.3-preview.17 434 10/20/2020
1.3.3-preview.15 499 10/1/2020
1.3.3-preview.11 434 9/30/2020
1.3.3-preview.9 407 9/30/2020
1.3.3-preview.7 426 9/27/2020
1.3.3-preview.5 453 9/27/2020
1.3.3-preview.1 424 9/24/2020
1.3.2-preview.3 427 9/19/2020
1.3.2-preview.1 511 8/25/2020
1.3.1-preview.6 472 7/2/2020
1.3.1-preview.3 510 6/30/2020
1.3.0 739 6/16/2020
1.3.0-rc.3 461 6/16/2020
1.3.0-preview.11 484 6/16/2020
1.3.0-preview.9 407 6/16/2020
1.3.0-preview.7 434 6/16/2020
1.3.0-alpha.12 495 6/16/2020
1.3.0-alpha.10 393 6/16/2020
1.3.0-alpha.8 429 6/16/2020
1.2.2 651 6/12/2020
1.2.2-preview.41 425 6/12/2020
1.2.2-preview.39 415 6/12/2020
1.2.2-preview.34 446 6/3/2020
1.2.2-preview.33 451 6/3/2020
1.2.2-preview.31 532 5/31/2020
1.2.2-preview.30 415 5/31/2020
1.2.2-preview.29 466 5/31/2020
1.2.2-preview.28 446 5/29/2020
1.2.2-preview.27 447 5/8/2020
1.2.2-preview.26 443 5/8/2020
1.2.2-preview.25 425 4/27/2020
1.2.2-preview.24 441 4/24/2020
1.2.2-preview.23 411 4/21/2020
1.2.2-preview.22 479 4/16/2020
1.2.2-preview.19 453 4/16/2020
1.2.2-preview.18 423 4/14/2020
1.2.2-preview.17 418 4/14/2020
1.2.2-preview.16 457 4/14/2020
1.2.2-preview.15 458 3/25/2020
1.2.2-preview.14 480 3/15/2020
1.2.2-preview.13 521 3/10/2020
1.2.2-preview.12 448 3/10/2020
1.2.2-preview.10 435 3/10/2020
1.2.2-preview.8 457 3/10/2020
1.2.2-preview.7 419 3/10/2020
1.2.2-preview.6 465 3/9/2020
1.2.2-preview.5 466 3/9/2020
1.2.2-preview.4 446 3/6/2020
1.2.2-preview.3 498 1/13/2020
1.2.2-preview.2 518 11/14/2019
1.2.2-preview.1 441 11/12/2019
1.2.2-alpha.42 423 6/12/2020
1.2.2-alpha.40 428 6/12/2020
1.2.2-alpha.38 449 6/11/2020
1.2.2-alpha.35 438 6/3/2020
1.2.2-alpha.34 432 6/3/2020
1.2.2-alpha.32 524 5/31/2020
1.2.2-alpha.31 460 5/31/2020
1.2.2-alpha.30 442 5/30/2020
1.2.2-alpha.29 459 5/29/2020
1.2.2-alpha.28 473 5/8/2020
1.2.2-alpha.27 431 5/8/2020
1.2.2-alpha.26 440 4/27/2020
1.2.2-alpha.23 475 4/16/2020
1.2.2-alpha.21 441 4/16/2020
1.2.2-alpha.20 438 4/16/2020
1.2.2-alpha.19 411 4/14/2020
1.2.2-alpha.18 425 4/14/2020
1.2.2-alpha.17 439 4/14/2020
1.2.2-alpha.16 457 3/25/2020
1.2.2-alpha.15 464 3/15/2020
1.2.2-alpha.14 412 3/10/2020
1.2.2-alpha.13 404 3/10/2020
1.2.2-alpha.11 416 3/10/2020
1.2.2-alpha.10 421 3/10/2020
1.2.2-alpha.9 454 3/10/2020
1.2.2-alpha.8 454 3/9/2020
1.2.2-alpha.7 448 3/9/2020
1.2.2-alpha.6 464 3/9/2020
1.2.1-preview.3 437 11/8/2019
1.2.1-preview.1 442 11/5/2019
1.2.0-preview.3 458 10/18/2019
1.1.0 809 10/17/2019
1.1.0-preview.3 464 10/17/2019
1.0.8-preview.7 473 10/17/2019
1.0.8-preview.5 482 10/15/2019
1.0.8-preview.4 450 9/30/2019
1.0.8-preview.1 485 8/30/2019
1.0.7-preview.1 485 8/30/2019
1.0.6-preview.33 486 8/19/2019
1.0.6-preview.30 463 7/19/2019
1.0.6-preview.26 475 6/23/2019
1.0.6-preview.19 497 6/22/2019
1.0.6-preview.17 493 6/18/2019
1.0.5-preview-028 717 4/5/2019
1.0.5-preview-026 696 4/5/2019