Http.Request is a value type that represents a HTTP request.

For more information on making HTTP requests, see Http.

function Http.Request(Url url) → Http.Request

Creates a Http.Request object for the url.

var req = Http.Request("")

property Url url

The request URL.

property Bool allowRedirects: true

When enabled, requests will transparently follow redirects returned by the remote server. Otherwise, the returned Http.Response will contain a 30x status code and you can manually decide whether or not to resubmit the request to the new location.

Any HTTP headers returned by the server - including cookies - from an intermediate request are discarded. If you need these headers, you must handle redirects manually.

function parameter(String name) → String

function setParameter(String name, String value)

Get and set request parameters.

In the case of a GET request, the parameters will be percent-encoded and included as the URL query string. If the request URL contained a query string, the request parameters will replace it.

For a POST request, they will be included as the request body, with a "application/x-www-form-urlencoded" content-type.

property String contentread only

property String contentTyperead only

The content and content-type to be sent with a POST request.

Both properties will return empty strings unless content has been set with the setContent() method.

function setContent(Json json)

function setContent(String type, String content)

Sets custom content for a POST request.

By default, the request parameters are included as the POST content, encoded as "application/x-www-form-urlencoded" data. This matches the behavior of data submitted through a HTML form and is what most web servers expect.

You can explicitly control the raw POST content by providing both the content-type and the content data. This data will be sent as-is to the remote server.

req.setContent("text/plain", "username: bob, password: secret")

When interacting with HTTP APIs that communicate using JSON, you can provide a Json object to be used as the POST content. The JSON object will be stringified into a compact form, and the content type set automatically to "application/json".

var json = { username: "bob", password: "secret" }

In both cases, the custom POST content overrides the request parameters.

function header(String name) → String

function setHeader(String name, String value)

Get and set request headers. HTTP header names are case-insensitive.

function cookie(String name) → String

function cookies() → Dictionary<String, String>

Return an individual cookie by name, or a dictionary of all the request's cookies.

function setCookie(String name, String value)

function setCookies(Dictionary<String, String> cookies)

Set a request's cookies.

setCookie() adds or modifies an existing request cookie.

setCookies() sets the request's cookies with one call. Any cookies that had been added prior to the call to setCookies() will be removed. After calling setCookies(), you can continue to add and modify individual cookies with setCookie().