Cosmos.Network.Http 2.0.0

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

<h1 align="center">CosmosHTTP Client 🚀</h1> <p> <a href="https://www.nuget.org/packages/Cosmos.Network.Http/" target="_blank"> <img alt="Version" src="https://img.shields.io/nuget/v/Cosmos.Network.Http.svg" /> </a> <a href="https://github.com/CosmosOS/Cosmos.Network.Http/blob/main/LICENSE.txt" target="_blank"> <img alt="License: BSD Clause 3 License" src="https://img.shields.io/badge/license-BSD License-yellow.svg" /> </a> </p>

CosmosHTTP is an HTTP/1.1 client made in C# for the Cosmos operating system construction kit.

Usage

Add the package to your kernel .csproj:

<ItemGroup>
    <PackageReference Include="Cosmos.Network.Http" Version="2.0.0" />
</ItemGroup>

The kernel needs networking (CosmosEnableNetwork, on by default), an IP configuration (DHCP or static) and, for host names, a DNS server. Send() runs the request on the calling thread and returns the response once it has arrived whole:

using System;
using System.IO;
using Cosmos.Network.Http;

HttpResponse response = new HttpRequest("http://httpforever.com/").Send();

Console.WriteLine($"{response.StatusCode} {response.ReasonPhrase}, {response.Content.Length} bytes");
File.WriteAllBytes("/0/index.html", response.Content);

Send() returns error statuses too; EnsureSuccessStatusCode() turns them into an HttpException, and GetString() decodes the body with the charset of its Content-Type:

string json = new HttpRequest("http://example.com/data.json").Send().EnsureSuccessStatusCode().GetString();

A request can set its method, body, headers, timeout and how many redirects it follows:

HttpResponse response = new HttpRequest("http://example.com/api")
{
    Method = "POST",
    Body = Encoding.UTF8.GetBytes("{\"name\":\"cosmos\"}"),
    Headers = { ["Content-Type"] = "application/json" },
    Timeout = 10_000,  // how long the server may stay silent, in milliseconds (15 s by default)
    MaxRedirects = 0,  // return redirects instead of following them (5 by default)
    // Optional: one line per response and redirect.
    Log = message => Cosmos.Kernel.System.Diagnostics.Log.WriteString(message + "\n"),
}.Send();

The Host header comes from the URL. Setting it in Headers reaches a virtual host by IP address:

new HttpRequest("http://34.223.124.45/") { Headers = { ["Host"] = "neverssl.com" } }.Send();

Limits

  • http:// only: there is no TLS, so https:// URLs, and redirects to them, throw.
  • Each request opens a connection of its own, and the server closes it once it has answered.
  • Responses come without content coding (Accept-Encoding: identity): a Cosmos kernel has no gzip to undo.
  • The whole body is held in memory.

Threads

Send() never waits in Thread.Sleep: it waits in Socket.Poll, which returns at once on a Cosmos kernel. So it runs on the kernel's main loop, which must never block, as well as on a thread of its own.

Authors

👤 @valentinbreiz

👤 @2881099 (the first version was inspired by TcpClientHttpRequest)

🤝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page.

📝 License

Copyright © 2023-2026 CosmosOS.

This project is BSD Clause 3 licensed.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 0 10/8/2026
2.1.0 75 10/3/2026
2.0.0 83 10/3/2026