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?       Only hookable?    

Common

Advanced

NameReturnSummary 
$http->setData($data)
$this

Set 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()
array

Set options array given to $sanitizer->url()

 

Request headers

NameReturnSummary 
$http->getHeaders()
array

Get all currently set request headers in an associative array

 
$http->getUserAgent()
string

Get the current user-agent header

 
$http->resetRequest()
None

Reset all request data

 
$http->setCookie(string $name, $value)
self

Set cookie(s) for http GET/POST/etc. request (currently used by curl option only)

 
$http->setHeader(string $key, string $value)
$this

Send an individual request header to send with GET/POST/etc. request

 
$http->setHeaders(array $headers)
$this

Set an array of request headers to send with GET/POST/etc. request

 
$http->setUserAgent(string $userAgent)
None

Set the current user-agent header

 

Response headers

NameReturnSummary 
$http->getResponseHeader()
array string null

Get the last HTTP response headers (normal array).

 
$http->getResponseHeaderValues()
array string null

Get last HTTP response headers with multi-value headers as arrays

 
$http->getResponseHeaders()
array string null

Get the last HTTP response headers (associative array)

 
$http->resetResponse()
None

Reset all response properties

 

HTTP codes

NameReturnSummary 
$http->getErrorCodes()
array

Return array of all possible HTTP error codes as (code => description)

 
$http->getHttpCode()
int string

Get last HTTP code

 
$http->getHttpCodes()
array

Return array of all possible HTTP codes as (code => description)

 
$http->getSuccessCodes()
array

Return array of all possible HTTP success codes as (code => description)

 

Settings

NameReturnSummary 
$http->getAllowSchemes()
array

Return array of allowed schemes

 
$http->getTimeout()
float

Get the number of seconds till connection times out

 
$http->setAllowSchemes($schemes)
$this

Set schemes WireHttp is allowed to access Default:[http, https]

 
$http->setTimeout($seconds)
$this

Set 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.252