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

// 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.


Name Return Summary  
WireHttp::download(string $fromURL, string $toFile) string Download a file from a URL and save it locally
WireHttp::get(string $url) bool or string Send a GET request to URL
WireHttp::getAllowSchemes() array Return array of allowed schemes
WireHttp::getError() string or array Get a string of the last error message
WireHttp::getErrorCodes() array Return array of all possible HTTP error codes as (code => description)
WireHttp::getHttpCode() int or string Get last HTTP code
WireHttp::getJSON(string $url) bool, array or object Send to a URL that responds with JSON (using GET request) and return the resulting array or object.
WireHttp::getResponseHeaders() array, string or null Get the last HTTP response headers (associative array)
WireHttp::getTimeout() float Get the number of seconds till connection times out
WireHttp::head(string $url) bool or array Send to a URL using a HEAD request
WireHttp::post(string $url) bool or string Send a POST request to a URL
WireHttp::send(string $url) bool or string Send the given $data array to a URL using given method (i.e. POST, GET, PUT, DELETE, etc.)
WireHttp::sendFile(string $filename) (nothing) Send the contents of the given filename to the current http connection.
WireHttp::set(string $key, $value) $this Set a variable to be included in the POST/GET request
WireHttp::setAllowSchemes($schemes) $this Set schemes WireHttp is allowed to access (default=[http, https])
WireHttp::setData(array $data) $this Set an array of data, removes any existing data
WireHttp::setHeader(string $key, string $value) $this Send an individual header to send
WireHttp::setHeaders(array $headers) $this Set an array of headers, removes any existing headers
WireHttp::setTimeout($seconds) $this Set the number of seconds till connection times out
WireHttp::status(string $url) bool, integer or string Send to a URL using a HEAD request and return the status code
WireHttp::statusText(string $url) bool or string Send to a URL using HEAD and return the status code and text like "200 OK"
WireHttp::validateURL(string $url) string Validate 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: