Function “requestHTTP”

function requestHTTP(method, url[, headers, body])

Performs a HTTP request

Performs a HTTP request and returns the reply as an object.

Parameters

NameTypeDescription
methodstringThe HTTP method to use (e.g. "GET" or "POST")
urlstringThe URL to request
headersarray of values (optional)An optional array of key/value objects to pass as additional request headers
bodyarray of bytes (optional)Optional contents for the request body

Return Value

Returns an object with the fields statusCode, headers and body.

Example

try {
	res = requestHTTP("GET", "http://bildhuus.com/");
	if (res.statusCode == 200)
		alert("bildhuus.com is reachable and OK");
	else
		alert("bildhuus.com is reachable, but returned " + res.statusCode);
} catch (err) {
	alert("bildhuus.com is not reachable: " + err);
}