nanoFramework.System.Net.Http.Server 1.5.196

Prefix Reserved
The specified version 1.0.6-preview.4 was not found. You have been taken to version 1.5.196.
dotnet add package nanoFramework.System.Net.Http.Server --version 1.5.196
                    
NuGet\Install-Package nanoFramework.System.Net.Http.Server -Version 1.5.196
                    
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.Server" Version="1.5.196" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nanoFramework.System.Net.Http.Server" Version="1.5.196" />
                    
Directory.Packages.props
<PackageReference Include="nanoFramework.System.Net.Http.Server" />
                    
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.Server --version 1.5.196
                    
#r "nuget: nanoFramework.System.Net.Http.Server, 1.5.196"
                    
#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.Server@1.5.196
                    
#: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.Server&version=1.5.196
                    
Install as a Cake Addin
#tool nuget:?package=nanoFramework.System.Net.Http.Server&version=1.5.196
                    
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-----");

In order to get a root certificate from a server, if you install OpenSSL, you can run the following command: openssl s_client -connect the.server-to-get-the-cert.com:443 -showcerts This will show you all the root certs used and present them as PEM. You can then copy/paste the one you need.

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);

Disposing the response

You MUST dispose the response sent but any of the request. The device memory is limited and the response content will never be disposed if not asked. Depending on the devices, you may have only 16 possible requests before you'll get an out of memory.

Here is few right patterns to make sure you'll dispose properly the response content:

using HttpResponseMessage response = client.Get(apiUrl);
// do whatever you want
// When the response object won't be used, it will be disposed

You can as well have an explicit using for a block:

using HttpResponseMessage response = client.Get(apiUrl)
{
  // do whatever you want
  // when exiting the block, the response will be disposed
}

Or explicitly dispose the response:

HttpResponseMessage response = client.Get(apiUrl);
// do whatever you want
// Dispose explicitly the content
response.Dispose();

In all cases, you MUST make ure you are disposing the response content.

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 (4)

Showing the top 4 NuGet packages that depend on nanoFramework.System.Net.Http.Server:

Package Downloads
nanoFramework.WebServer

This is a simple multithread WebServer supporting simple controller and event based calls. Perfect for .NET nanoFramework REST API based project. Supports both HTTPS and HTTP. If serving files from local storage is a requirement, please use instead the 'nanoFramework.WebServer.FileSystem' nuget.

nanoFramework.WebServer.FileSystem

This is a simple multithread WebServer supporting simple controller and event based calls. Perfect for .NET nanoFramework REST API based project. Support all type of Http Methods. Perfect for simple embedded web pages, with Support of file on a storage (USB, SD Card, in Memory). Supports both HTTPS and HTTP. Use this version if you want to serve local files and have support for System.IO.FileSystem on your device. Otherwise use 'nanoFramework.WebServer' nuget.

nanoFramework.WebServer.Mcp

This is a simple Model Context Protocol (MCP) multithread WebServer supporting tools for integration with AI Agents. Perfect for .NET nanoFramework to be integrated with AI solutions. Supports both HTTPS and HTTP, Authentication, Strong Typing, Automatic Discovery. This comes also with the nanoFramework WebServer. Allowing to create a REST API based project with ease as well.

nf.HomeAssistant.MqttDiscovery

A lightweight library for .NET nanoFramework that simplifies Home Assistant MQTT Auto Discovery, letting your IoT devices register entities automatically without manual configuration.

GitHub repositories (2)

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

Repository Stars
nanoframework/Samples
🍬 Code samples from the nanoFramework team used in testing, proof of concepts and other explorational endeavours
nanoframework/nanoFramework.IoT.Device
📦 This repo includes .NET nanoFramework implementations for various sensors, chips, displays, hats and drivers
Version Downloads Last Updated
1.5.196 1,549 6/2/2025
1.5.195 470 4/24/2025
1.5.193 560 4/2/2025
1.5.192 729 3/26/2025
1.5.191 607 3/26/2025
1.5.189 539 3/10/2025
1.5.188 326 3/10/2025
1.5.187 319 3/10/2025
1.5.186 283 3/10/2025
1.5.184 445 3/3/2025
1.5.183 423 2/27/2025
1.5.182 236 2/27/2025
1.5.181 319 2/25/2025
1.5.180 186 2/25/2025
1.5.179 151 2/25/2025
1.5.178 248 2/25/2025
1.5.177 160 2/25/2025
1.5.175 567 2/5/2025
1.5.172 786 1/30/2025
1.5.171 245 1/30/2025
1.5.170 229 1/30/2025
1.5.169 249 1/30/2025
1.5.165 341 1/27/2025
1.5.162 490 1/6/2025
1.5.161 148 1/6/2025
1.5.159 138 1/6/2025
1.5.158 155 1/6/2025
1.5.157 307 1/2/2025
1.5.150 1,374 9/26/2024
1.5.145 419 7/30/2024
1.5.138 992 5/13/2024
1.5.136 404 5/10/2024
1.5.134 611 4/8/2024
1.5.132 291 4/8/2024
1.5.130 452 4/3/2024
1.5.128 298 4/3/2024
1.5.125 782 1/29/2024
1.5.118 606 1/24/2024
1.5.113 6,730 11/10/2023
1.5.110 222 11/9/2023
1.5.108 327 11/9/2023
1.5.106 460 11/3/2023
1.5.104 658 10/10/2023
1.5.102 370 10/4/2023
1.5.99 689 8/8/2023
1.5.97 483 7/27/2023
1.5.95 343 7/27/2023
1.5.84 1,238 2/17/2023
1.5.82 709 1/24/2023
1.5.78 1,210 12/28/2022
1.5.75 459 12/28/2022
1.5.73 451 12/28/2022
1.5.70 617 12/27/2022
1.5.68 478 12/22/2022
1.5.61 792 11/23/2022
1.5.54 967 10/26/2022
1.5.52 523 10/26/2022
1.5.50 574 10/26/2022
1.5.48 745 10/25/2022
1.5.45 551 10/25/2022
1.5.43 810 10/24/2022
1.5.41 581 10/24/2022
1.5.39 552 10/24/2022
1.5.37 564 10/23/2022
1.5.35 822 10/23/2022
1.5.30 886 10/10/2022
1.5.27 558 10/8/2022
1.5.24 1,174 9/22/2022
1.5.22 865 9/22/2022
1.5.20 1,520 9/15/2022
1.5.18 629 9/15/2022
1.5.13 1,434 8/5/2022
1.5.10 858 8/4/2022
1.5.8 586 8/4/2022
1.5.6 559 8/4/2022
1.5.4 843 8/3/2022
1.5.2 886 8/3/2022
1.4.0.25 856 8/3/2022
1.4.0.23 1,209 6/13/2022
1.4.0.21 920 6/8/2022
1.4.0.19 881 6/8/2022
1.4.0.14 997 5/26/2022
1.4.0.12 697 5/18/2022
1.4.0.10 684 5/3/2022
1.4.0 1,199 3/28/2022
1.4.0-preview.52 268 3/28/2022
1.4.0-preview.51 254 3/28/2022
1.4.0-preview.50 254 3/28/2022
1.4.0-preview.48 232 3/28/2022
1.4.0-preview.47 234 3/28/2022
1.4.0-preview.46 253 3/28/2022
1.4.0-preview.44 269 3/17/2022
1.4.0-preview.43 268 3/17/2022
1.4.0-preview.42 248 3/14/2022
1.4.0-preview.41 227 3/14/2022
1.4.0-preview.40 233 3/14/2022
1.4.0-preview.39 251 3/14/2022
1.4.0-preview.37 236 3/14/2022
1.4.0-preview.36 245 3/8/2022
1.4.0-preview.35 229 3/8/2022
1.4.0-preview.33 279 3/4/2022
1.4.0-preview.32 233 3/3/2022
1.4.0-preview.31 238 3/2/2022
1.4.0-preview.29 251 2/28/2022
1.4.0-preview.28 278 2/24/2022
1.4.0-preview.26 279 2/17/2022
1.4.0-preview.24 263 2/17/2022
1.4.0-preview.22 286 2/6/2022
1.4.0-preview.21 261 2/4/2022
1.4.0-preview.19 275 2/4/2022
1.4.0-preview.18 266 1/28/2022
1.4.0-preview.16 260 1/28/2022
1.4.0-preview.15 248 1/28/2022
1.4.0-preview.13 262 1/28/2022
1.4.0-preview.12 255 1/21/2022
1.4.0-preview.6 353 1/12/2022
1.4.0-preview.5 251 1/12/2022
1.4.0-preview.4 244 1/11/2022
1.4.0-preview.3 251 1/11/2022
1.3.7-preview.8 276 1/5/2022
1.3.7-preview.7 270 1/3/2022
1.3.7-preview.6 260 1/3/2022
1.3.7-preview.5 286 1/3/2022
1.3.7-preview.4 277 12/30/2021
1.3.7-preview.3 273 12/28/2021
1.3.6 720 12/3/2021
1.3.6-preview.23 268 12/3/2021
1.3.6-preview.21 274 12/3/2021
1.3.6-preview.20 264 12/2/2021
1.3.6-preview.19 270 12/2/2021
1.3.6-preview.18 283 12/2/2021
1.3.6-preview.17 258 12/2/2021
1.3.6-preview.16 264 12/2/2021
1.3.6-preview.14 267 12/2/2021
1.3.6-preview.12 268 12/2/2021
1.3.6-preview.10 271 12/1/2021
1.3.6-preview.7 290 12/1/2021
1.3.6-preview.1 418 11/11/2021
1.3.5-preview.8 346 10/22/2021
1.3.5-preview.5 304 10/18/2021
1.3.4 1,016 7/16/2021
1.3.4-preview.78 288 7/16/2021
1.3.4-preview.76 282 7/16/2021
1.3.4-preview.74 288 7/16/2021
1.3.4-preview.72 301 7/15/2021
1.3.4-preview.70 290 7/14/2021
1.3.4-preview.68 430 6/19/2021
1.3.4-preview.66 372 6/19/2021
1.3.4-preview.64 304 6/17/2021
1.3.4-preview.62 334 6/7/2021
1.3.4-preview.60 286 6/7/2021
1.3.4-preview.58 324 6/7/2021
1.3.4-preview.56 660 6/6/2021
1.3.4-preview.54 692 6/3/2021
1.3.4-preview.52 295 6/2/2021
1.3.4-preview.50 296 6/1/2021
1.3.4-preview.48 320 6/1/2021
1.3.4-preview.41 330 5/25/2021
1.3.4-preview.39 370 5/21/2021
1.3.4-preview.37 343 5/20/2021
1.3.4-preview.35 296 5/19/2021
1.3.4-preview.33 308 5/19/2021
1.3.4-preview.31 306 5/19/2021
1.3.4-preview.29 312 5/15/2021
1.3.4-preview.27 276 5/15/2021
1.3.4-preview.25 273 5/15/2021
1.3.4-preview.23 310 5/13/2021
1.3.4-preview.22 294 5/13/2021
1.3.4-preview.20 326 5/11/2021
1.3.4-preview.18 358 5/6/2021
1.3.4-preview.16 298 5/6/2021
1.3.4-preview.14 274 5/5/2021
1.3.4-preview.13 272 5/5/2021
1.3.4-preview.10 394 4/10/2021
1.3.4-preview.9 317 4/9/2021
1.3.4-preview.7 324 4/5/2021
1.3.3-preview.65 370 3/20/2021
1.3.3-preview.62 330 3/19/2021
1.3.3-preview.60 315 3/17/2021
1.3.3-preview.57 281 3/17/2021
1.3.3-preview.55 364 3/2/2021
1.3.3-preview.50 670 1/19/2021
1.3.3-preview.47 340 1/6/2021
1.3.3-preview.40 538 12/29/2020
1.3.3-preview.34 437 12/7/2020
1.3.3-preview.32 347 12/7/2020
1.3.3-preview.27 470 11/3/2020
1.3.3-preview.25 372 10/26/2020
1.3.3-preview.23 390 10/21/2020
1.3.3-preview.17 374 10/20/2020
1.3.3-preview.15 435 10/1/2020
1.3.3-preview.11 376 9/30/2020
1.3.3-preview.9 395 9/30/2020
1.3.3-preview.7 401 9/27/2020
1.3.3-preview.5 394 9/27/2020
1.3.3-preview.1 379 9/24/2020
1.3.2-preview.3 387 9/19/2020
1.3.2-preview.1 411 8/25/2020
1.3.1-preview.6 415 7/2/2020
1.3.1-preview.3 431 6/30/2020
1.3.0 734 6/16/2020
1.3.0-rc.3 441 6/16/2020
1.3.0-preview.11 425 6/16/2020
1.3.0-preview.9 358 6/16/2020
1.3.0-preview.7 355 6/16/2020
1.3.0-alpha.12 447 6/16/2020
1.3.0-alpha.10 374 6/16/2020
1.3.0-alpha.8 381 6/16/2020
1.2.2 624 6/12/2020
1.2.2-preview.41 360 6/12/2020
1.2.2-preview.39 387 6/12/2020
1.2.2-preview.34 378 6/3/2020
1.2.2-preview.33 413 6/3/2020
1.2.2-preview.31 472 5/31/2020
1.2.2-preview.30 377 5/31/2020
1.2.2-preview.29 414 5/31/2020
1.2.2-preview.28 423 5/29/2020
1.2.2-preview.27 393 5/8/2020
1.2.2-preview.26 421 5/8/2020
1.2.2-preview.25 407 4/27/2020
1.2.2-preview.24 403 4/24/2020
1.2.2-preview.23 382 4/21/2020
1.2.2-preview.22 407 4/16/2020
1.2.2-preview.19 403 4/16/2020
1.2.2-preview.18 380 4/14/2020
1.2.2-preview.17 377 4/14/2020
1.2.2-preview.16 373 4/14/2020
1.2.2-preview.15 414 3/25/2020
1.2.2-preview.14 434 3/15/2020
1.2.2-preview.13 471 3/10/2020
1.2.2-preview.12 374 3/10/2020
1.2.2-preview.10 381 3/10/2020
1.2.2-preview.8 375 3/10/2020
1.2.2-preview.7 381 3/10/2020
1.2.2-preview.6 402 3/9/2020
1.2.2-preview.5 423 3/9/2020
1.2.2-preview.4 397 3/6/2020
1.2.2-preview.3 425 1/13/2020
1.2.2-preview.2 408 11/14/2019
1.2.2-preview.1 405 11/12/2019
1.2.2-alpha.42 362 6/12/2020
1.2.2-alpha.40 390 6/12/2020
1.2.2-alpha.38 406 6/11/2020
1.2.2-alpha.35 361 6/3/2020
1.2.2-alpha.34 390 6/3/2020
1.2.2-alpha.32 479 5/31/2020
1.2.2-alpha.31 401 5/31/2020
1.2.2-alpha.30 399 5/30/2020
1.2.2-alpha.29 390 5/29/2020
1.2.2-alpha.28 395 5/8/2020
1.2.2-alpha.27 394 5/8/2020
1.2.2-alpha.26 373 4/27/2020
1.2.2-alpha.23 407 4/16/2020
1.2.2-alpha.21 404 4/16/2020
1.2.2-alpha.20 403 4/16/2020
1.2.2-alpha.19 377 4/14/2020
1.2.2-alpha.18 373 4/14/2020
1.2.2-alpha.17 410 4/14/2020
1.2.2-alpha.16 446 3/25/2020
1.2.2-alpha.15 431 3/15/2020
1.2.2-alpha.14 366 3/10/2020
1.2.2-alpha.13 399 3/10/2020
1.2.2-alpha.11 373 3/10/2020
1.2.2-alpha.10 405 3/10/2020
1.2.2-alpha.9 380 3/10/2020
1.2.2-alpha.8 416 3/9/2020
1.2.2-alpha.7 396 3/9/2020
1.2.2-alpha.6 427 3/9/2020
1.2.1-preview.3 402 11/8/2019
1.2.1-preview.1 413 11/5/2019
1.2.0-preview.3 395 10/18/2019
1.1.0 727 10/17/2019
1.1.0-preview.3 431 10/17/2019
1.0.8-preview.7 425 10/17/2019
1.0.8-preview.5 407 10/15/2019
1.0.8-preview.4 402 9/30/2019
1.0.8-preview.1 412 8/30/2019
1.0.7-preview.1 425 8/30/2019
1.0.6-preview.33 439 8/19/2019
1.0.6-preview.30 422 7/19/2019
1.0.6-preview.26 424 6/23/2019
1.0.6-preview.19 449 6/22/2019
1.0.6-preview.17 456 6/18/2019
1.0.5-preview-028 699 4/5/2019