Skip to content
CShift0.45

HttpRequest

Struct · namespace System.Net · Since 0.42

struct HttpRequest

A request: the method, the URL, the headers and the body.

var request = HttpRequest.Create("POST", "https://example.com/api");
request.SetHeader("Content-Type", "application/json");
request.Body = "{\"hello\": 1}";
var response = try Http.Send(request);

A request is a value; its headers are a List of "Name: value" lines, so copies share them (like every list). It can be passed to a thread function (the thread gets its own copy), which keeps a window responsive while a request waits for its answer.

Name Description
Method GET, POST, PUT, PATCH, DELETE, …
Url http:// or https://, the host, an optional port, the path and the query.
Headers The lines Name: value of the headers.
Body The body (UTF-8); empty for none.
TimeoutMilliseconds How long the request may take in all, in milliseconds (0: 60 seconds).
string Method

GET, POST, PUT, PATCH, DELETE, … (GET when empty).

string Url

http:// or https://, the host, an optional port, the path and the query.

List<string> Headers

The lines Name: value of the headers.

string Body

The body (UTF-8); empty for none.

int TimeoutMilliseconds

How long the request may take in all, in milliseconds (0: 60 seconds).

Name Description
Create A request with method to url, without headers or body.
static HttpRequest Create(string method, string url)

A request with method to url, without headers or body.

Name Description
SetHeader Adds a header, or replaces the one of the same name (the case of the name does not matter).
void SetHeader(StringSlice name, StringSlice value)

Adds a header, or replaces the one of the same name (the case of the name does not matter).

Panics when the name or the value contains a line break.