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

Twitter updates

  • New post: This week ProcessWire ProMailer has been released, plus we’ve got a nice upgrade in our community support forum, and more— More
    15 March 2019
  • New post: This week we look at the latest version of ProcessWire, 3.0.127 with nearly 30 new commits resolving dozens of older issue reports and a couple useful new features— More
    1 March 2019
  • New post: This week we take a look at what’s in ProcessWire 3.0.126 which focuses largely on resolving issue reports, but also includes a handy new Page if() method— More
    15 February 2019

Latest news

  • ProcessWire Weekly #253
    In the 253rd issue of ProcessWire Weekly we'll introduce the ProMailer Pro module, cover the upgrade made to our support forum software, check out Sanitizer Transliterate, and pick a new site of the week. Read on!
    Weekly.pw / 16 March 2019
  • ProcessWire ProMailer now available
    This week ProcessWire ProMailer has been released, plus we’ve got a nice upgrade in our community support forum, and more.
    Blog / 15 March 2019
  • Subscribe to weekly ProcessWire news

“…building with ProcessWire was a breeze, I really love all the flexibility the system provides. I can’t imagine using any other CMS in the future.” —Thomas Aull