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 448 11/19/2025
1.5.199 299 11/13/2025
1.5.196 596 6/2/2025
1.5.195 303 4/24/2025
1.5.193 314 4/2/2025
1.5.192 542 3/26/2025
1.5.191 552 3/26/2025
1.5.189 248 3/10/2025
1.5.188 251 3/10/2025
1.5.187 236 3/10/2025
1.5.186 250 3/10/2025
1.5.184 195 3/3/2025
1.5.183 215 2/27/2025
1.5.182 151 2/27/2025
1.5.181 164 2/25/2025
1.5.180 171 2/25/2025
1.5.179 184 2/25/2025
1.5.178 160 2/25/2025
1.5.177 176 2/25/2025
1.5.175 250 2/5/2025
1.5.172 196 1/30/2025
1.5.171 158 1/30/2025
1.5.170 186 1/30/2025
1.5.169 175 1/30/2025
1.5.165 179 1/27/2025
1.5.162 261 1/6/2025
1.5.161 153 1/6/2025
1.5.159 162 1/6/2025
1.5.158 160 1/6/2025
1.5.157 197 1/2/2025
1.5.150 582 9/26/2024
1.5.145 280 7/30/2024
1.5.138 383 5/13/2024
1.5.136 278 5/10/2024
1.5.134 278 4/8/2024
1.5.132 171 4/8/2024
1.5.130 230 4/3/2024
1.5.128 176 4/3/2024
1.5.125 379 1/29/2024
1.5.118 201 1/24/2024
1.5.113 498 11/10/2023
1.5.110 193 11/9/2023
1.5.108 238 11/9/2023
1.5.106 219 11/3/2023
1.5.104 349 10/10/2023
1.5.102 285 10/4/2023
1.5.99 423 8/8/2023
1.5.97 386 7/27/2023
1.5.95 247 7/27/2023
1.5.84 748 2/17/2023
1.5.82 503 1/24/2023
1.5.78 504 12/28/2022
1.5.75 433 12/28/2022
1.5.73 462 12/28/2022
1.5.70 435 12/27/2022
1.5.68 477 12/22/2022
1.5.61 657 11/23/2022
1.5.54 623 10/26/2022
1.5.52 501 10/26/2022
1.5.50 566 10/26/2022
1.5.48 525 10/25/2022
1.5.45 549 10/25/2022
1.5.43 548 10/24/2022
1.5.41 587 10/24/2022
1.5.39 548 10/24/2022
1.5.37 542 10/23/2022
1.5.35 551 10/23/2022
1.5.30 583 10/10/2022
1.5.27 518 10/8/2022
1.5.24 603 9/22/2022
1.5.22 581 9/22/2022
1.5.20 676 9/15/2022
1.5.18 576 9/15/2022
1.5.13 805 8/5/2022
1.5.10 545 8/4/2022
1.5.8 563 8/4/2022
1.5.6 586 8/4/2022
1.5.4 578 8/3/2022
1.5.2 605 8/3/2022
1.4.0.25 586 8/3/2022
1.4.0.23 768 6/13/2022
1.4.0.21 580 6/8/2022
1.4.0.19 588 6/8/2022
1.4.0.14 640 5/26/2022
1.4.0.12 620 5/18/2022
1.4.0.10 643 5/3/2022
1.4.0 736 3/28/2022
1.4.0-preview.52 256 3/28/2022
1.4.0-preview.51 241 3/28/2022
1.4.0-preview.50 261 3/28/2022
1.4.0-preview.48 273 3/28/2022
1.4.0-preview.47 260 3/28/2022
1.4.0-preview.46 242 3/28/2022
1.4.0-preview.44 289 3/17/2022
1.4.0-preview.43 250 3/17/2022
1.4.0-preview.42 281 3/14/2022
1.4.0-preview.41 249 3/14/2022
1.4.0-preview.40 263 3/14/2022
1.4.0-preview.39 270 3/14/2022
1.4.0-preview.37 246 3/14/2022
1.4.0-preview.36 260 3/8/2022
1.4.0-preview.35 271 3/8/2022
1.4.0-preview.33 260 3/4/2022
1.4.0-preview.32 268 3/3/2022
1.4.0-preview.31 253 3/2/2022
1.4.0-preview.29 292 2/28/2022
1.4.0-preview.28 323 2/24/2022
1.4.0-preview.26 310 2/17/2022
1.4.0-preview.24 255 2/17/2022
1.4.0-preview.22 300 2/6/2022
1.4.0-preview.21 297 2/4/2022
1.4.0-preview.19 296 2/4/2022
1.4.0-preview.18 269 1/28/2022
1.4.0-preview.16 269 1/28/2022
1.4.0-preview.15 274 1/28/2022
1.4.0-preview.13 291 1/28/2022
1.4.0-preview.12 283 1/21/2022
1.4.0-preview.6 280 1/12/2022
1.4.0-preview.5 288 1/12/2022
1.4.0-preview.4 288 1/11/2022
1.4.0-preview.3 283 1/11/2022
1.3.7-preview.8 294 1/5/2022
1.3.7-preview.7 282 1/3/2022
1.3.7-preview.6 298 1/3/2022
1.3.7-preview.5 275 1/3/2022
1.3.7-preview.4 264 12/30/2021
1.3.7-preview.3 294 12/28/2021
1.3.6 713 12/3/2021
1.3.6-preview.23 294 12/3/2021
1.3.6-preview.21 292 12/3/2021
1.3.6-preview.20 277 12/2/2021
1.3.6-preview.19 291 12/2/2021
1.3.6-preview.18 302 12/2/2021
1.3.6-preview.17 279 12/2/2021
1.3.6-preview.16 303 12/2/2021
1.3.6-preview.14 307 12/2/2021
1.3.6-preview.12 275 12/2/2021
1.3.6-preview.10 300 12/1/2021
1.3.6-preview.7 280 12/1/2021
1.3.6-preview.1 352 11/11/2021
1.3.5-preview.8 290 10/22/2021
1.3.5-preview.5 301 10/18/2021
1.3.4 1,314 7/16/2021
1.3.4-preview.78 309 7/16/2021
1.3.4-preview.76 292 7/16/2021
1.3.4-preview.74 291 7/16/2021
1.3.4-preview.72 304 7/15/2021
1.3.4-preview.70 317 7/14/2021
1.3.4-preview.68 758 6/19/2021
1.3.4-preview.66 393 6/19/2021
1.3.4-preview.64 291 6/17/2021
1.3.4-preview.62 331 6/7/2021
1.3.4-preview.60 300 6/7/2021
1.3.4-preview.58 356 6/7/2021
1.3.4-preview.56 337 6/6/2021
1.3.4-preview.54 338 6/3/2021
1.3.4-preview.52 326 6/2/2021
1.3.4-preview.50 328 6/1/2021
1.3.4-preview.48 317 6/1/2021
1.3.4-preview.41 356 5/25/2021
1.3.4-preview.39 370 5/21/2021
1.3.4-preview.37 388 5/20/2021
1.3.4-preview.35 326 5/19/2021
1.3.4-preview.33 299 5/19/2021
1.3.4-preview.31 322 5/19/2021
1.3.4-preview.29 325 5/15/2021
1.3.4-preview.27 322 5/15/2021
1.3.4-preview.25 329 5/15/2021
1.3.4-preview.23 302 5/13/2021
1.3.4-preview.22 315 5/13/2021
1.3.4-preview.20 344 5/11/2021
1.3.4-preview.18 365 5/6/2021
1.3.4-preview.16 304 5/6/2021
1.3.4-preview.14 316 5/5/2021
1.3.4-preview.13 292 5/5/2021
1.3.4-preview.10 353 4/10/2021
1.3.4-preview.9 359 4/9/2021
1.3.4-preview.7 310 4/5/2021
1.3.3-preview.65 373 3/20/2021
1.3.3-preview.62 353 3/19/2021
1.3.3-preview.60 328 3/17/2021
1.3.3-preview.57 325 3/17/2021
1.3.3-preview.55 323 3/2/2021
1.3.3-preview.50 555 1/19/2021
1.3.3-preview.47 325 1/6/2021
1.3.3-preview.40 351 12/29/2020
1.3.3-preview.34 404 12/7/2020
1.3.3-preview.32 360 12/7/2020
1.3.3-preview.27 389 11/3/2020
1.3.3-preview.25 393 10/26/2020
1.3.3-preview.23 426 10/21/2020
1.3.3-preview.17 414 10/20/2020
1.3.3-preview.15 483 10/1/2020
1.3.3-preview.11 414 9/30/2020
1.3.3-preview.9 389 9/30/2020
1.3.3-preview.7 409 9/27/2020
1.3.3-preview.5 436 9/27/2020
1.3.3-preview.1 410 9/24/2020
1.3.2-preview.3 409 9/19/2020
1.3.2-preview.1 496 8/25/2020
1.3.1-preview.6 455 7/2/2020
1.3.1-preview.3 490 6/30/2020
1.3.0 720 6/16/2020
1.3.0-rc.3 440 6/16/2020
1.3.0-preview.11 474 6/16/2020
1.3.0-preview.9 384 6/16/2020
1.3.0-preview.7 414 6/16/2020
1.3.0-alpha.12 479 6/16/2020
1.3.0-alpha.10 373 6/16/2020
1.3.0-alpha.8 413 6/16/2020
1.2.2 629 6/12/2020
1.2.2-preview.41 407 6/12/2020
1.2.2-preview.39 399 6/12/2020
1.2.2-preview.34 428 6/3/2020
1.2.2-preview.33 437 6/3/2020
1.2.2-preview.31 515 5/31/2020
1.2.2-preview.30 395 5/31/2020
1.2.2-preview.29 445 5/31/2020
1.2.2-preview.28 422 5/29/2020
1.2.2-preview.27 430 5/8/2020
1.2.2-preview.26 425 5/8/2020
1.2.2-preview.25 405 4/27/2020
1.2.2-preview.24 424 4/24/2020
1.2.2-preview.23 398 4/21/2020
1.2.2-preview.22 462 4/16/2020
1.2.2-preview.19 433 4/16/2020
1.2.2-preview.18 407 4/14/2020
1.2.2-preview.17 403 4/14/2020
1.2.2-preview.16 436 4/14/2020
1.2.2-preview.15 440 3/25/2020
1.2.2-preview.14 467 3/15/2020
1.2.2-preview.13 502 3/10/2020
1.2.2-preview.12 430 3/10/2020
1.2.2-preview.10 416 3/10/2020
1.2.2-preview.8 439 3/10/2020
1.2.2-preview.7 403 3/10/2020
1.2.2-preview.6 450 3/9/2020
1.2.2-preview.5 448 3/9/2020
1.2.2-preview.4 428 3/6/2020
1.2.2-preview.3 480 1/13/2020
1.2.2-preview.2 500 11/14/2019
1.2.2-preview.1 420 11/12/2019
1.2.2-alpha.42 406 6/12/2020
1.2.2-alpha.40 409 6/12/2020
1.2.2-alpha.38 433 6/11/2020
1.2.2-alpha.35 422 6/3/2020
1.2.2-alpha.34 413 6/3/2020
1.2.2-alpha.32 507 5/31/2020
1.2.2-alpha.31 443 5/31/2020
1.2.2-alpha.30 426 5/30/2020
1.2.2-alpha.29 442 5/29/2020
1.2.2-alpha.28 454 5/8/2020
1.2.2-alpha.27 411 5/8/2020
1.2.2-alpha.26 422 4/27/2020
1.2.2-alpha.23 459 4/16/2020
1.2.2-alpha.21 424 4/16/2020
1.2.2-alpha.20 424 4/16/2020
1.2.2-alpha.19 395 4/14/2020
1.2.2-alpha.18 405 4/14/2020
1.2.2-alpha.17 421 4/14/2020
1.2.2-alpha.16 440 3/25/2020
1.2.2-alpha.15 446 3/15/2020
1.2.2-alpha.14 399 3/10/2020
1.2.2-alpha.13 387 3/10/2020
1.2.2-alpha.11 397 3/10/2020
1.2.2-alpha.10 404 3/10/2020
1.2.2-alpha.9 438 3/10/2020
1.2.2-alpha.8 434 3/9/2020
1.2.2-alpha.7 430 3/9/2020
1.2.2-alpha.6 443 3/9/2020
1.2.1-preview.3 420 11/8/2019
1.2.1-preview.1 428 11/5/2019
1.2.0-preview.3 440 10/18/2019
1.1.0 793 10/17/2019
1.1.0-preview.3 445 10/17/2019
1.0.8-preview.7 452 10/17/2019
1.0.8-preview.5 463 10/15/2019
1.0.8-preview.4 430 9/30/2019
1.0.8-preview.1 465 8/30/2019
1.0.7-preview.1 469 8/30/2019
1.0.6-preview.33 469 8/19/2019
1.0.6-preview.30 443 7/19/2019
1.0.6-preview.26 462 6/23/2019
1.0.6-preview.19 480 6/22/2019
1.0.6-preview.17 474 6/18/2019
1.0.5-preview-028 693 4/5/2019
1.0.5-preview-026 680 4/5/2019