Http
Struct · namespace System.Net · Since 0.42
struct HttpSends 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).
Static methods
Section titled “Static methods”| 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). |
Supported
Section titled “Supported”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
HttpError.InvalidUrl: the URL is not an http or https URL.HttpError.CannotResolve: the host is unknown.HttpError.CannotConnect: the server cannot be reached, or the TLS connection failed.HttpError.Timeout: the time of the request is over.HttpError.Failed: sending or receiving failed.HttpError.NotSupported: this platform has no HTTP client.
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, …).
ParseUrl
Section titled “ParseUrl”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).
Escape
Section titled “Escape”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).