nanoFramework.System.Net.Http.Server 1.5.10

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.Server --version 1.5.10
                    
NuGet\Install-Package nanoFramework.System.Net.Http.Server -Version 1.5.10
                    
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.10" />
                    
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.10" />
                    
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.10
                    
#r "nuget: nanoFramework.System.Net.Http.Server, 1.5.10"
                    
#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.
#addin nuget:?package=nanoFramework.System.Net.Http.Server&version=1.5.10
                    
Install nanoFramework.System.Net.Http.Server as a Cake Addin
#tool nuget:?package=nanoFramework.System.Net.Http.Server&version=1.5.10
                    
Install nanoFramework.System.Net.Http.Server 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 (2)

Showing the top 2 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.

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.192 492 3/26/2025
1.5.191 447 3/26/2025
1.5.189 372 3/10/2025
1.5.188 214 3/10/2025
1.5.187 219 3/10/2025
1.5.186 209 3/10/2025
1.5.184 321 3/3/2025
1.5.183 266 2/27/2025
1.5.182 141 2/27/2025
1.5.181 220 2/25/2025
1.5.180 96 2/25/2025
1.5.179 95 2/25/2025
1.5.178 143 2/25/2025
1.5.177 99 2/25/2025
1.5.175 427 2/5/2025
1.5.172 528 1/30/2025
1.5.171 146 1/30/2025
1.5.170 134 1/30/2025
1.5.169 149 1/30/2025
1.5.165 225 1/27/2025
1.5.162 386 1/6/2025
1.5.161 97 1/6/2025
1.5.159 85 1/6/2025
1.5.158 96 1/6/2025
1.5.157 206 1/2/2025
1.5.150 1,147 9/26/2024
1.5.145 331 7/30/2024
1.5.138 790 5/13/2024
1.5.136 298 5/10/2024
1.5.134 494 4/8/2024
1.5.132 223 4/8/2024
1.5.130 324 4/3/2024
1.5.128 219 4/3/2024
1.5.125 654 1/29/2024
1.5.118 446 1/24/2024
1.5.113 4,417 11/10/2023
1.5.110 159 11/9/2023
1.5.108 255 11/9/2023
1.5.106 362 11/3/2023
1.5.104 537 10/10/2023
1.5.102 314 10/4/2023
1.5.99 593 8/8/2023
1.5.97 364 7/27/2023
1.5.95 242 7/27/2023
1.5.84 1,110 2/17/2023
1.5.82 599 1/24/2023
1.5.78 1,048 12/28/2022
1.5.75 369 12/28/2022
1.5.73 367 12/28/2022
1.5.70 527 12/27/2022
1.5.68 399 12/22/2022
1.5.61 695 11/23/2022
1.5.54 854 10/26/2022
1.5.52 436 10/26/2022
1.5.50 494 10/26/2022
1.5.48 638 10/25/2022
1.5.45 461 10/25/2022
1.5.43 685 10/24/2022
1.5.41 491 10/24/2022
1.5.39 468 10/24/2022
1.5.37 475 10/23/2022
1.5.35 724 10/23/2022
1.5.30 772 10/10/2022
1.5.27 462 10/8/2022
1.5.24 1,018 9/22/2022
1.5.22 760 9/22/2022
1.5.20 1,378 9/15/2022
1.5.18 521 9/15/2022
1.5.13 1,315 8/5/2022
1.5.10 744 8/4/2022
1.5.8 491 8/4/2022
1.5.6 463 8/4/2022
1.5.4 736 8/3/2022
1.5.2 753 8/3/2022
1.4.0.25 738 8/3/2022
1.4.0.23 1,083 6/13/2022
1.4.0.21 805 6/8/2022
1.4.0.19 765 6/8/2022
1.4.0.14 875 5/26/2022
1.4.0.12 571 5/18/2022
1.4.0.10 584 5/3/2022
1.4.0 1,074 3/28/2022
1.4.0-preview.52 161 3/28/2022
1.4.0-preview.51 152 3/28/2022
1.4.0-preview.50 148 3/28/2022
1.4.0-preview.48 142 3/28/2022
1.4.0-preview.47 148 3/28/2022
1.4.0-preview.46 148 3/28/2022
1.4.0-preview.44 187 3/17/2022
1.4.0-preview.43 158 3/17/2022
1.4.0-preview.42 162 3/14/2022
1.4.0-preview.41 142 3/14/2022
1.4.0-preview.40 148 3/14/2022
1.4.0-preview.39 150 3/14/2022
1.4.0-preview.37 150 3/14/2022
1.4.0-preview.36 166 3/8/2022
1.4.0-preview.35 149 3/8/2022
1.4.0-preview.33 177 3/4/2022
1.4.0-preview.32 148 3/3/2022
1.4.0-preview.31 154 3/2/2022
1.4.0-preview.29 170 2/28/2022
1.4.0-preview.28 190 2/24/2022
1.4.0-preview.26 175 2/17/2022
1.4.0-preview.24 162 2/17/2022
1.4.0-preview.22 205 2/6/2022
1.4.0-preview.21 174 2/4/2022
1.4.0-preview.19 170 2/4/2022
1.4.0-preview.18 181 1/28/2022
1.4.0-preview.16 172 1/28/2022
1.4.0-preview.15 168 1/28/2022
1.4.0-preview.13 172 1/28/2022
1.4.0-preview.12 170 1/21/2022
1.4.0-preview.6 267 1/12/2022
1.4.0-preview.5 165 1/12/2022
1.4.0-preview.4 163 1/11/2022
1.4.0-preview.3 170 1/11/2022
1.3.7-preview.8 186 1/5/2022
1.3.7-preview.7 187 1/3/2022
1.3.7-preview.6 178 1/3/2022
1.3.7-preview.5 170 1/3/2022
1.3.7-preview.4 170 12/30/2021
1.3.7-preview.3 187 12/28/2021
1.3.6 611 12/3/2021
1.3.6-preview.23 185 12/3/2021
1.3.6-preview.21 174 12/3/2021
1.3.6-preview.20 176 12/2/2021
1.3.6-preview.19 185 12/2/2021
1.3.6-preview.18 176 12/2/2021
1.3.6-preview.17 175 12/2/2021
1.3.6-preview.16 180 12/2/2021
1.3.6-preview.14 180 12/2/2021
1.3.6-preview.12 181 12/2/2021
1.3.6-preview.10 190 12/1/2021
1.3.6-preview.7 183 12/1/2021
1.3.6-preview.1 335 11/11/2021
1.3.5-preview.8 260 10/22/2021
1.3.5-preview.5 221 10/18/2021
1.3.4 910 7/16/2021
1.3.4-preview.78 177 7/16/2021
1.3.4-preview.76 194 7/16/2021
1.3.4-preview.74 184 7/16/2021
1.3.4-preview.72 189 7/15/2021
1.3.4-preview.70 206 7/14/2021
1.3.4-preview.68 343 6/19/2021
1.3.4-preview.66 291 6/19/2021
1.3.4-preview.64 200 6/17/2021
1.3.4-preview.62 245 6/7/2021
1.3.4-preview.60 204 6/7/2021
1.3.4-preview.58 237 6/7/2021
1.3.4-preview.56 576 6/6/2021
1.3.4-preview.54 593 6/3/2021
1.3.4-preview.52 196 6/2/2021
1.3.4-preview.50 209 6/1/2021
1.3.4-preview.48 214 6/1/2021
1.3.4-preview.41 245 5/25/2021
1.3.4-preview.39 255 5/21/2021
1.3.4-preview.37 255 5/20/2021
1.3.4-preview.35 213 5/19/2021
1.3.4-preview.33 200 5/19/2021
1.3.4-preview.31 215 5/19/2021
1.3.4-preview.29 200 5/15/2021
1.3.4-preview.27 188 5/15/2021
1.3.4-preview.25 187 5/15/2021
1.3.4-preview.23 224 5/13/2021
1.3.4-preview.22 189 5/13/2021
1.3.4-preview.20 234 5/11/2021
1.3.4-preview.18 266 5/6/2021
1.3.4-preview.16 188 5/6/2021
1.3.4-preview.14 189 5/5/2021
1.3.4-preview.13 185 5/5/2021
1.3.4-preview.10 281 4/10/2021
1.3.4-preview.9 227 4/9/2021
1.3.4-preview.7 231 4/5/2021
1.3.3-preview.65 279 3/20/2021
1.3.3-preview.62 238 3/19/2021
1.3.3-preview.60 203 3/17/2021
1.3.3-preview.57 195 3/17/2021
1.3.3-preview.55 268 3/2/2021
1.3.3-preview.50 559 1/19/2021
1.3.3-preview.47 245 1/6/2021
1.3.3-preview.40 440 12/29/2020
1.3.3-preview.34 320 12/7/2020
1.3.3-preview.32 242 12/7/2020
1.3.3-preview.27 374 11/3/2020
1.3.3-preview.25 251 10/26/2020
1.3.3-preview.23 289 10/21/2020
1.3.3-preview.17 276 10/20/2020
1.3.3-preview.15 343 10/1/2020
1.3.3-preview.11 263 9/30/2020
1.3.3-preview.9 272 9/30/2020
1.3.3-preview.7 288 9/27/2020
1.3.3-preview.5 296 9/27/2020
1.3.3-preview.1 260 9/24/2020
1.3.2-preview.3 282 9/19/2020
1.3.2-preview.1 290 8/25/2020
1.3.1-preview.6 304 7/2/2020
1.3.1-preview.3 336 6/30/2020
1.3.0 618 6/16/2020
1.3.0-rc.3 318 6/16/2020
1.3.0-preview.11 331 6/16/2020
1.3.0-preview.9 265 6/16/2020
1.3.0-preview.7 257 6/16/2020
1.3.0-alpha.12 328 6/16/2020
1.3.0-alpha.10 258 6/16/2020
1.3.0-alpha.8 262 6/16/2020
1.2.2 514 6/12/2020
1.2.2-preview.41 267 6/12/2020
1.2.2-preview.39 287 6/12/2020
1.2.2-preview.34 278 6/3/2020
1.2.2-preview.33 293 6/3/2020
1.2.2-preview.31 375 5/31/2020
1.2.2-preview.30 276 5/31/2020
1.2.2-preview.29 320 5/31/2020
1.2.2-preview.28 296 5/29/2020
1.2.2-preview.27 292 5/8/2020
1.2.2-preview.26 294 5/8/2020
1.2.2-preview.25 279 4/27/2020
1.2.2-preview.24 277 4/24/2020
1.2.2-preview.23 262 4/21/2020
1.2.2-preview.22 308 4/16/2020
1.2.2-preview.19 301 4/16/2020
1.2.2-preview.18 279 4/14/2020
1.2.2-preview.17 274 4/14/2020
1.2.2-preview.16 271 4/14/2020
1.2.2-preview.15 311 3/25/2020
1.2.2-preview.14 309 3/15/2020
1.2.2-preview.13 325 3/10/2020
1.2.2-preview.12 274 3/10/2020
1.2.2-preview.10 280 3/10/2020
1.2.2-preview.8 273 3/10/2020
1.2.2-preview.7 279 3/10/2020
1.2.2-preview.6 301 3/9/2020
1.2.2-preview.5 304 3/9/2020
1.2.2-preview.4 296 3/6/2020
1.2.2-preview.3 322 1/13/2020
1.2.2-preview.2 304 11/14/2019
1.2.2-preview.1 297 11/12/2019
1.2.2-alpha.42 264 6/12/2020
1.2.2-alpha.40 293 6/12/2020
1.2.2-alpha.38 309 6/11/2020
1.2.2-alpha.35 268 6/3/2020
1.2.2-alpha.34 293 6/3/2020
1.2.2-alpha.32 382 5/31/2020
1.2.2-alpha.31 300 5/31/2020
1.2.2-alpha.30 301 5/30/2020
1.2.2-alpha.29 295 5/29/2020
1.2.2-alpha.28 295 5/8/2020
1.2.2-alpha.27 293 5/8/2020
1.2.2-alpha.26 271 4/27/2020
1.2.2-alpha.23 304 4/16/2020
1.2.2-alpha.21 304 4/16/2020
1.2.2-alpha.20 304 4/16/2020
1.2.2-alpha.19 277 4/14/2020
1.2.2-alpha.18 272 4/14/2020
1.2.2-alpha.17 278 4/14/2020
1.2.2-alpha.16 317 3/25/2020
1.2.2-alpha.15 320 3/15/2020
1.2.2-alpha.14 267 3/10/2020
1.2.2-alpha.13 273 3/10/2020
1.2.2-alpha.11 274 3/10/2020
1.2.2-alpha.10 277 3/10/2020
1.2.2-alpha.9 279 3/10/2020
1.2.2-alpha.8 302 3/9/2020
1.2.2-alpha.7 294 3/9/2020
1.2.2-alpha.6 322 3/9/2020
1.2.1-preview.3 297 11/8/2019
1.2.1-preview.1 308 11/5/2019
1.2.0-preview.3 288 10/18/2019
1.1.0 600 10/17/2019
1.1.0-preview.3 299 10/17/2019
1.0.8-preview.7 294 10/17/2019
1.0.8-preview.5 305 10/15/2019
1.0.8-preview.4 299 9/30/2019
1.0.8-preview.1 308 8/30/2019
1.0.7-preview.1 316 8/30/2019
1.0.6-preview.33 314 8/19/2019
1.0.6-preview.30 316 7/19/2019
1.0.6-preview.26 317 6/23/2019
1.0.6-preview.19 344 6/22/2019
1.0.6-preview.17 348 6/18/2019
1.0.5-preview-028 571 4/5/2019