Skip to content
CShift0.45

Http

Struct · namespace System.Net · Since 0.42

struct Http

Sends HTTP requests.

using System;
using System.Net;
var response = try Http.Get("https://example.com/");
if (response.IsSuccess())
Console.WriteLine(response.Body);

A request waits until the response has arrived (or the time is over): in a program with a window, send it from a thread function and look whether the thread is done in the frames (Thread<T>.IsCompleted).

Name Description
Supported Whether this platform can send requests (Windows; Linux with libcurl).
Send Sends request and waits for the response.
Get A GET request to url.
Post A POST request to url with body of the type contentType (application/json, text/plain, …).
ParseUrl The parts of an http or https URL, or null if it is not one (another scheme, no host, a port that is not a number in 1..65535, a space or a line break in it).
Escape text for a URL: letters, digits and -._~ stay, every other byte becomes %XX (a query value, a part of a path).
static bool Supported()

Whether this platform can send requests (Windows; Linux with libcurl).

static HttpError<HttpResponse> Send(HttpRequest request)

Sends request and waits for the response. Redirects (301, 302, 303, 307, 308) are followed; a body that the server compressed (gzip, deflate) is given decompressed.

Errors

static HttpError<HttpResponse> Get(string url)

A GET request to url.

static HttpError<HttpResponse> Post(string url, string contentType, string body)

A POST request to url with body of the type contentType (application/json, text/plain, …).

static Optional<HttpUrl> ParseUrl(StringSlice url)

The parts of an http or https URL, or null if it is not one (another scheme, no host, a port that is not a number in 1..65535, a space or a line break in it).

static string Escape(StringSlice text)

text for a URL: letters, digits and -._~ stay, every other byte becomes %XX (a query value, a part of a path).