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 
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) 
setValidateURLOptions()
arraySet options array given to $sanitizer->url() 

Request headers

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

Response headers

NameReturnSummary 
getResponseHeader()
array string nullGet the last HTTP response headers (normal array). 
getResponseHeaderValues()
array string nullGet last HTTP response headers with multi-value headers as arrays 
getResponseHeaders()
array string nullGet the last HTTP response headers (associative array) 

HTTP codes

NameReturnSummary 
getErrorCodes()
arrayReturn array of all possible HTTP error codes as (code => description) 
getHttpCode()
int stringGet last HTTP code 
getHttpCodes()
arrayReturn array of all possible HTTP codes as (code => description) 
getSuccessCodes()
arrayReturn array of all possible HTTP success codes as (code => description) 

Settings

NameReturnSummary 
getAllowSchemes()
arrayReturn array of allowed schemes 
getTimeout()
floatGet the number of seconds till connection times out 
setAllowSchemes($schemes)
$thisSet schemes WireHttp is allowed to access (default=[http, https]) 
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.251