PHP Class Unirest\Request

Exibir arquivo Open project: mashape/unirest-php Class Usage Examples

Public Methods

Method Description
auth ( string $username = '', string $password = '', integer $method = CURLAUTH_BASIC ) Set authentication method to use
buildHTTPCurlQuery ( array | object $data, boolean | string $parent = false ) : array This function is useful for serializing multidimensional arrays, and avoid getting the 'Array to string conversion' notice
clearCurlOpts ( ) Clear all the default headers
clearDefaultHeaders ( ) Clear all the default headers
connect ( string $url, array $headers = [], mixed $parameters = null, string $username = null, string $password = null ) : unirest\Response Send a CONNECT request to a URL
cookie ( string $cookie ) Set a cookie string for enabling cookie handling
cookieFile ( string $cookieFile ) Set a cookie file path for enabling cookie handling
curlOpt ( string $name, string $value ) : string Set a new default header to send on every request
curlOpts ( array $options ) : array Set curl options to send on every request
defaultHeader ( string $name, string $value ) : string Set a new default header to send on every request
defaultHeaders ( array $headers ) : array Set default headers to send on every request
delete ( string $url, array $headers = [], mixed $body = null, string $username = null, string $password = null ) : unirest\Response Send DELETE request to a URL
get ( string $url, array $headers = [], mixed $parameters = null, string $username = null, string $password = null ) : unirest\Response Send a GET request to a URL
getCurlHandle ( )
getFormattedHeaders ( $headers )
getInfo ( $opt = false )
head ( string $url, array $headers = [], mixed $parameters = null, string $username = null, string $password = null ) : unirest\Response Send a HEAD request to a URL
jsonOpts ( boolean $assoc = false, integer $depth = 512, integer $options ) : array Set JSON decode mode
options ( string $url, array $headers = [], mixed $parameters = null, string $username = null, string $password = null ) : unirest\Response Send a OPTIONS request to a URL
patch ( string $url, array $headers = [], mixed $body = null, string $username = null, string $password = null ) : unirest\Response Send PATCH request to a URL
post ( string $url, array $headers = [], mixed $body = null, string $username = null, string $password = null ) : unirest\Response Send POST request to a URL
proxy ( string $address, integer $port = 1080, integer $type = CURLPROXY_HTTP, boolean $tunnel = false ) Set proxy to use
proxyAuth ( string $username = '', string $password = '', integer $method = CURLAUTH_BASIC ) Set proxy authentication method to use
put ( string $url, array $headers = [], mixed $body = null, string $username = null, string $password = null ) : unirest\Response Send PUT request to a URL
send ( Unirest\Method | string $method, string $url, mixed $body = null, array $headers = [], string $username = null, string $password = null ) : unirest\Response Send a cURL request
setMashapeKey ( string $key ) : string Set a Mashape key to send on every request as a header Obtain your Mashape key by browsing one of your Mashape applications on https://www.mashape.com
timeout ( integer $seconds ) : integer Set a timeout
trace ( string $url, array $headers = [], mixed $body = null, string $username = null, string $password = null ) : unirest\Response Send TRACE request to a URL
verifyHost ( boolean $enabled ) : boolean Verify SSL host
verifyPeer ( boolean $enabled ) : boolean Verify SSL peer

Private Methods

Method Description
encodeUrl ( string $url ) : string Ensure that a URL is encoded and safe to use with cURL
getArrayFromQuerystring ( $query )
getHeaderString ( $key, $val )
mergeCurlOptions ( array &$existing_options, array $new_options ) : array

Method Details

auth() public static method

Set authentication method to use
public static auth ( string $username = '', string $password = '', integer $method = CURLAUTH_BASIC )
$username string authentication username
$password string authentication password
$method integer authentication method

buildHTTPCurlQuery() public static method

This function is useful for serializing multidimensional arrays, and avoid getting the 'Array to string conversion' notice
public static buildHTTPCurlQuery ( array | object $data, boolean | string $parent = false ) : array
$data array | object array to flatten.
$parent boolean | string parent key or false if no parent
return array

clearCurlOpts() public static method

Clear all the default headers
public static clearCurlOpts ( )

clearDefaultHeaders() public static method

Clear all the default headers
public static clearDefaultHeaders ( )

connect() public static method

Send a CONNECT request to a URL
public static connect ( string $url, array $headers = [], mixed $parameters = null, string $username = null, string $password = null ) : unirest\Response
$url string URL to send the CONNECT request to
$headers array additional headers to send
$parameters mixed parameters to send in the querystring
$username string Basic Authentication username (deprecated)
$password string Basic Authentication password (deprecated)
return unirest\Response

cookieFile() public static method

$cookieFile must be a correct path with write permission
public static cookieFile ( string $cookieFile )
$cookieFile string - path to file for saving cookie

curlOpt() public static method

Set a new default header to send on every request
public static curlOpt ( string $name, string $value ) : string
$name string header name
$value string header value
return string

curlOpts() public static method

Set curl options to send on every request
public static curlOpts ( array $options ) : array
$options array options array
return array

defaultHeader() public static method

Set a new default header to send on every request
public static defaultHeader ( string $name, string $value ) : string
$name string header name
$value string header value
return string

defaultHeaders() public static method

Set default headers to send on every request
public static defaultHeaders ( array $headers ) : array
$headers array headers array
return array

delete() public static method

Send DELETE request to a URL
public static delete ( string $url, array $headers = [], mixed $body = null, string $username = null, string $password = null ) : unirest\Response
$url string URL to send the DELETE request to
$headers array additional headers to send
$body mixed DELETE body data
$username string Basic Authentication username (deprecated)
$password string Basic Authentication password (deprecated)
return unirest\Response

get() public static method

Send a GET request to a URL
public static get ( string $url, array $headers = [], mixed $parameters = null, string $username = null, string $password = null ) : unirest\Response
$url string URL to send the GET request to
$headers array additional headers to send
$parameters mixed parameters to send in the querystring
$username string Authentication username (deprecated)
$password string Authentication password (deprecated)
return unirest\Response

getCurlHandle() public static method

public static getCurlHandle ( )

getFormattedHeaders() public static method

public static getFormattedHeaders ( $headers )

getInfo() public static method

public static getInfo ( $opt = false )

head() public static method

Send a HEAD request to a URL
public static head ( string $url, array $headers = [], mixed $parameters = null, string $username = null, string $password = null ) : unirest\Response
$url string URL to send the HEAD request to
$headers array additional headers to send
$parameters mixed parameters to send in the querystring
$username string Basic Authentication username (deprecated)
$password string Basic Authentication password (deprecated)
return unirest\Response

jsonOpts() public static method

Set JSON decode mode
public static jsonOpts ( boolean $assoc = false, integer $depth = 512, integer $options ) : array
$assoc boolean When TRUE, returned objects will be converted into associative arrays.
$depth integer User specified recursion depth.
$options integer Bitmask of JSON decode options. Currently only JSON_BIGINT_AS_STRING is supported (default is to cast large integers as floats)
return array

options() public static method

Send a OPTIONS request to a URL
public static options ( string $url, array $headers = [], mixed $parameters = null, string $username = null, string $password = null ) : unirest\Response
$url string URL to send the OPTIONS request to
$headers array additional headers to send
$parameters mixed parameters to send in the querystring
$username string Basic Authentication username
$password string Basic Authentication password
return unirest\Response

patch() public static method

Send PATCH request to a URL
public static patch ( string $url, array $headers = [], mixed $body = null, string $username = null, string $password = null ) : unirest\Response
$url string URL to send the PATCH request to
$headers array additional headers to send
$body mixed PATCH body data
$username string Basic Authentication username (deprecated)
$password string Basic Authentication password (deprecated)
return unirest\Response

post() public static method

Send POST request to a URL
public static post ( string $url, array $headers = [], mixed $body = null, string $username = null, string $password = null ) : unirest\Response
$url string URL to send the POST request to
$headers array additional headers to send
$body mixed POST body data
$username string Basic Authentication username (deprecated)
$password string Basic Authentication password (deprecated)
return unirest\Response response

proxy() public static method

Set proxy to use
public static proxy ( string $address, integer $port = 1080, integer $type = CURLPROXY_HTTP, boolean $tunnel = false )
$address string proxy address
$port integer proxy port
$type integer (Available options for this are CURLPROXY_HTTP, CURLPROXY_HTTP_1_0 CURLPROXY_SOCKS4, CURLPROXY_SOCKS5, CURLPROXY_SOCKS4A and CURLPROXY_SOCKS5_HOSTNAME)
$tunnel boolean enable/disable tunneling

proxyAuth() public static method

Set proxy authentication method to use
public static proxyAuth ( string $username = '', string $password = '', integer $method = CURLAUTH_BASIC )
$username string authentication username
$password string authentication password
$method integer authentication method

put() public static method

Send PUT request to a URL
public static put ( string $url, array $headers = [], mixed $body = null, string $username = null, string $password = null ) : unirest\Response
$url string URL to send the PUT request to
$headers array additional headers to send
$body mixed PUT body data
$username string Basic Authentication username (deprecated)
$password string Basic Authentication password (deprecated)
return unirest\Response

send() public static method

Send a cURL request
public static send ( Unirest\Method | string $method, string $url, mixed $body = null, array $headers = [], string $username = null, string $password = null ) : unirest\Response
$method Unirest\Method | string HTTP method to use
$url string URL to send the request to
$body mixed request body
$headers array additional headers to send
$username string Authentication username (deprecated)
$password string Authentication password (deprecated)
return unirest\Response

setMashapeKey() public static method

Note: Mashape provides 2 keys for each application: a 'Testing' and a 'Production' one. Be aware of which key you are using and do not share your Production key.
public static setMashapeKey ( string $key ) : string
$key string Mashape key
return string

timeout() public static method

Set a timeout
public static timeout ( integer $seconds ) : integer
$seconds integer timeout value in seconds
return integer

trace() public static method

Send TRACE request to a URL
public static trace ( string $url, array $headers = [], mixed $body = null, string $username = null, string $password = null ) : unirest\Response
$url string URL to send the TRACE request to
$headers array additional headers to send
$body mixed TRACE body data
$username string Basic Authentication username (deprecated)
$password string Basic Authentication password (deprecated)
return unirest\Response

verifyHost() public static method

Verify SSL host
public static verifyHost ( boolean $enabled ) : boolean
$enabled boolean enable SSL host verification, by default is true
return boolean

verifyPeer() public static method

Verify SSL peer
public static verifyPeer ( boolean $enabled ) : boolean
$enabled boolean enable SSL verification, by default is true
return boolean