WireHttp enables you to send HTTP requests to URLs, download files, and more.

// Get an instance of WireHttp
$http = new WireHttp();
// Get the contents of a URL
$response = $http->get("http://domain.com/path/");
if($response !== false) {
  echo "Successful response: " . $sanitizer->entities($response);
} else {
  echo "HTTP request failed: " . $http->getError();

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the WireHttp class also inherits all the methods and properties of: Wire.

Show “$http”             Show Arguments        


$http->download(string $fromURL, string $toFile)
stringDownload a file from a URL and save it locally
$http->get(string $url)
bool or stringSend a GET request to URL
arrayReturn array of allowed schemes
string or arrayGet a string of the last error message
arrayReturn array of all possible HTTP error codes as (code => description)
int or stringGet last HTTP code
$http->getJSON(string $url)
bool, array or objectSend to a URL that responds with JSON (using GET request) and return the resulting array or object.
array, string or nullGet the last HTTP response headers (associative array)
floatGet the number of seconds till connection times out
$http->head(string $url)
bool or arraySend to a URL using a HEAD request
$http->post(string $url)
bool or stringSend a POST request to a URL
$http->send(string $url)
bool or stringSend the given $data array to a URL using given method (i.e. POST, GET, PUT, DELETE, etc.)
$http->sendFile(string $filename)
(nothing)Send the contents of the given filename to the current http connection.
$http->set(string $key, $value)
$thisSet a variable to be included in the POST/GET request
$thisSet schemes WireHttp is allowed to access (default=[http, https])
$http->setData(array $data)
$thisSet an array of data, removes any existing data
$http->setHeader(string $key, string $value)
$thisSend an individual header to send
$http->setHeaders(array $headers)
$thisSet an array of headers, removes any existing headers
$thisSet the number of seconds till connection times out
$http->status(string $url)
bool, integer or stringSend to a URL using a HEAD request and return the status code
$http->statusText(string $url)
bool or stringSend to a URL using HEAD and return the status code and text like "200 OK"
$http->validateURL(string $url)
stringValidate a URL for WireHttp use

Additional methods and properties

In addition to the methods and properties above, WireHttp also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.60