HttpRequest
Struct · namespace System.Net · Since 0.42
struct HttpRequestA 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.
Fields
Section titled “Fields”| 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). |
Method
Section titled “Method”string MethodGET, POST, PUT, PATCH, DELETE, … (GET when empty).
string Urlhttp:// or https://, the host, an optional port, the path and the query.
Headers
Section titled “Headers”List<string> HeadersThe lines Name: value of the headers.
string BodyThe body (UTF-8); empty for none.
TimeoutMilliseconds
Section titled “TimeoutMilliseconds”int TimeoutMillisecondsHow long the request may take in all, in milliseconds (0: 60 seconds).
Static methods
Section titled “Static methods”| Name | Description |
|---|---|
Create |
A request with method to url, without headers or body. |
Create
Section titled “Create”static HttpRequest Create(string method, string url)A request with method to url, without headers or body.
Methods
Section titled “Methods”| Name | Description |
|---|---|
SetHeader |
Adds a header, or replaces the one of the same name (the case of the name does not matter). |
SetHeader
Section titled “SetHeader”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.