WireHttp class

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 $var?             Show args?        

Common

NameReturnSummary 
$http->download(string $fromURL, string $toFile)
stringDownload a file from a URL and save it locally 
$http->get(string $url)
bool stringSend a GET request to URL 
$http->getAllowSchemes()
arrayReturn array of allowed schemes 
$http->getError()
string arrayGet a string of the last error message 
$http->getErrorCodes()
arrayReturn array of all possible HTTP error codes as (code => description) 
$http->getHttpCode()
int stringGet last HTTP code 
$http->getHttpCodes()
arrayReturn array of all possible HTTP codes as (code => description) 
$http->getJSON(string $url)
bool array objectSend to a URL that responds with JSON (using GET request) and return the resulting array or object. 
$http->getResponseHeaderValues()
array string nullGet last HTTP response headers with multi-value headers as arrays 
$http->getResponseHeaders()
array string nullGet the last HTTP response headers (associative array) 
$http->getSuccessCodes()
arrayReturn array of all possible HTTP success codes as (code => description) 
$http->getTimeout()
floatGet the number of seconds till connection times out 
$http->getUserAgent()
stringGet the current user-agent header 
$http->head(string $url)
bool arraySend to a URL using a HEAD request 
$http->post(string $url)
bool stringSend a POST request to a URL 
$http->send(string $url)
bool 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 
$http->setAllowSchemes($schemes)
$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 
$http->setTimeout($seconds)
$thisSet the number of seconds till connection times out 
$http->setValidateURLOptions()
arraySet options array given to $sanitizer->url() 
$http->status(string $url)
bool integer stringSend to a URL using a HEAD request and return the status code 
$http->statusText(string $url)
bool 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.130

Twitter updates

  • New post: ProcessWire 3.0.131 adds support for partial/resumable downloads and http stream delivery, and contains several updates to our comments system, among other updates— More
    3 May 2019
  • New post: Quietly and without interruption this week, the ProcessWire.com website (and all subdomains) moved from a single static server to a load-balanced multi-server environment, giving us even more horsepower and redundancy than before— More
    19 April 2019
  • New post: With ProcessWire 3.0.130, this week we’ll take a detailed look at a few useful new API additions made in the last few weeks, along with examples of each—More
    12 April 2019

Latest news

  • ProcessWire Weekly #262
    The 262nd issue of ProcessWire Weekly will cover the latest module updates, both Pro modules and non-commercial ones. We've also got some highlights from the support forum, and a beautiful new site of the week. Read on!
    Weekly.pw / 18 May 2019
  • Lots of module updates
    In this post we take a quick look at the new version of ProFields Repeater Matrix, yet another new version of FormBuilder, and a new version of the GoogleClientAPI module.
    Blog / 17 May 2019
  • Subscribe to weekly ProcessWire news

“The end client and designer love the ease at which they can update the website. Training beyond how to log in wasn’t even necessary since ProcessWire’s default interface is straightforward.” —Jonathan Lahijani