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->getError()
string arrayGet a string of the last error message 
$http->sendStatusHeader($status)
(nothing)Send an HTTP status header 

Advanced

NameReturnSummary 
$http->setData($data)
$thisSet an array of data, or string of raw data to send with next GET/POST/etc. request (overwriting the existing data or rawData) 
$http->setValidateURLOptions()
arraySet options array given to $sanitizer->url() 

HTTP requests

Request headers

NameReturnSummary 
$http->getHeaders()
arrayGet all currently set request headers in an associative array 
$http->getUserAgent()
stringGet the current user-agent header 
$http->setCookie(string $name, $value)
selfSet cookie(s) for http GET/POST/etc. request (currently used by curl option only) 
$http->setHeader(string $key, string $value)
$thisSend an individual request header to send with GET/POST/etc. request 
$http->setHeaders(array $headers)
$thisSet an array of request headers to send with GET/POST/etc. request 
$http->setUserAgent(string $userAgent)
(nothing)Set the current user-agent header 

Response headers

NameReturnSummary 
$http->getResponseHeader()
array string nullGet the last HTTP response headers (normal array). 
$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 codes

NameReturnSummary 
$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->getSuccessCodes()
arrayReturn array of all possible HTTP success codes as (code => description) 

Settings

NameReturnSummary 
$http->getAllowSchemes()
arrayReturn array of allowed schemes 
$http->getTimeout()
floatGet the number of seconds till connection times out 
$http->setAllowSchemes($schemes)
$thisSet schemes WireHttp is allowed to access (default=[http, https]) 
$http->setTimeout($seconds)
$thisSet the number of seconds till connection times out 

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

Twitter updates

    Error retrieving Twitter status

Latest news

  • ProcessWire Weekly #471
    In the 471st issue of ProcessWire Weekly we're going to check out the latest core updates, introduce a new third party textformatter module for video embedding, and more. Read on!
    Weekly.pw / 20 May 2023
  • A look at the new Page Edit Restore module
    The new Page Edit Restore module helps to prevent page edits in the admin from getting lost when the user’s session is lost. This post covers it in detail.
    Blog / 12 May 2023
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits