|
|
|
|
@@ -15,6 +15,7 @@ class Request
|
|
|
|
|
private static $jsonOpts = array();
|
|
|
|
|
private static $socketTimeout = null;
|
|
|
|
|
private static $verifyPeer = true;
|
|
|
|
|
private static $verifyHost = true;
|
|
|
|
|
|
|
|
|
|
private static $auth = array (
|
|
|
|
|
'user' => '',
|
|
|
|
|
@@ -56,6 +57,16 @@ class Request
|
|
|
|
|
return self::$verifyPeer = $enabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verify SSL host
|
|
|
|
|
*
|
|
|
|
|
* @param bool $enabled enable SSL host verification, by default is true
|
|
|
|
|
*/
|
|
|
|
|
public static function verifyHost($enabled)
|
|
|
|
|
{
|
|
|
|
|
return self::$verifyHost = $enabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a timeout
|
|
|
|
|
*
|
|
|
|
|
@@ -213,7 +224,7 @@ class Request
|
|
|
|
|
* @param mixed $parameters parameters to send in the querystring
|
|
|
|
|
* @param string $username Authentication username (deprecated)
|
|
|
|
|
* @param string $password Authentication password (deprecated)
|
|
|
|
|
* @return string|stdObj response string or stdObj if response is json-decodable
|
|
|
|
|
* @return Unirest\Response
|
|
|
|
|
*/
|
|
|
|
|
public static function get($url, $headers = array(), $parameters = null, $username = null, $password = null)
|
|
|
|
|
{
|
|
|
|
|
@@ -227,7 +238,7 @@ class Request
|
|
|
|
|
* @param mixed $parameters parameters to send in the querystring
|
|
|
|
|
* @param string $username Basic Authentication username (deprecated)
|
|
|
|
|
* @param string $password Basic Authentication password (deprecated)
|
|
|
|
|
* @return string|stdObj response string or stdObj if response is json-decodable
|
|
|
|
|
* @return Unirest\Response
|
|
|
|
|
*/
|
|
|
|
|
public static function head($url, $headers = array(), $parameters = null, $username = null, $password = null)
|
|
|
|
|
{
|
|
|
|
|
@@ -241,7 +252,7 @@ class Request
|
|
|
|
|
* @param mixed $parameters parameters to send in the querystring
|
|
|
|
|
* @param string $username Basic Authentication username
|
|
|
|
|
* @param string $password Basic Authentication password
|
|
|
|
|
* @return string|stdObj response string or stdObj if response is json-decodable
|
|
|
|
|
* @return Unirest\Response
|
|
|
|
|
*/
|
|
|
|
|
public static function options($url, $headers = array(), $parameters = null, $username = null, $password = null)
|
|
|
|
|
{
|
|
|
|
|
@@ -255,7 +266,7 @@ class Request
|
|
|
|
|
* @param mixed $parameters parameters to send in the querystring
|
|
|
|
|
* @param string $username Basic Authentication username (deprecated)
|
|
|
|
|
* @param string $password Basic Authentication password (deprecated)
|
|
|
|
|
* @return string|stdObj response string or stdObj if response is json-decodable
|
|
|
|
|
* @return Unirest\Response
|
|
|
|
|
*/
|
|
|
|
|
public static function connect($url, $headers = array(), $parameters = null, $username = null, $password = null)
|
|
|
|
|
{
|
|
|
|
|
@@ -269,7 +280,7 @@ class Request
|
|
|
|
|
* @param mixed $body POST body data
|
|
|
|
|
* @param string $username Basic Authentication username (deprecated)
|
|
|
|
|
* @param string $password Basic Authentication password (deprecated)
|
|
|
|
|
* @return string|stdObj response string or stdObj if response is json-decodable
|
|
|
|
|
* @return Unirest\Response response
|
|
|
|
|
*/
|
|
|
|
|
public static function post($url, $headers = array(), $body = null, $username = null, $password = null)
|
|
|
|
|
{
|
|
|
|
|
@@ -283,7 +294,7 @@ class Request
|
|
|
|
|
* @param mixed $body DELETE body data
|
|
|
|
|
* @param string $username Basic Authentication username (deprecated)
|
|
|
|
|
* @param string $password Basic Authentication password (deprecated)
|
|
|
|
|
* @return string|stdObj response string or stdObj if response is json-decodable
|
|
|
|
|
* @return Unirest\Response
|
|
|
|
|
*/
|
|
|
|
|
public static function delete($url, $headers = array(), $body = null, $username = null, $password = null)
|
|
|
|
|
{
|
|
|
|
|
@@ -297,7 +308,7 @@ class Request
|
|
|
|
|
* @param mixed $body PUT body data
|
|
|
|
|
* @param string $username Basic Authentication username (deprecated)
|
|
|
|
|
* @param string $password Basic Authentication password (deprecated)
|
|
|
|
|
* @return string|stdObj response string or stdObj if response is json-decodable
|
|
|
|
|
* @return Unirest\Response
|
|
|
|
|
*/
|
|
|
|
|
public static function put($url, $headers = array(), $body = null, $username = null, $password = null)
|
|
|
|
|
{
|
|
|
|
|
@@ -311,7 +322,7 @@ class Request
|
|
|
|
|
* @param mixed $body PATCH body data
|
|
|
|
|
* @param string $username Basic Authentication username (deprecated)
|
|
|
|
|
* @param string $password Basic Authentication password (deprecated)
|
|
|
|
|
* @return string|stdObj response string or stdObj if response is json-decodable
|
|
|
|
|
* @return Unirest\Response
|
|
|
|
|
*/
|
|
|
|
|
public static function patch($url, $headers = array(), $body = null, $username = null, $password = null)
|
|
|
|
|
{
|
|
|
|
|
@@ -325,7 +336,7 @@ class Request
|
|
|
|
|
* @param mixed $body TRACE body data
|
|
|
|
|
* @param string $username Basic Authentication username (deprecated)
|
|
|
|
|
* @param string $password Basic Authentication password (deprecated)
|
|
|
|
|
* @return string|stdObj response string or stdObj if response is json-decodable
|
|
|
|
|
* @return Unirest\Response
|
|
|
|
|
*/
|
|
|
|
|
public static function trace($url, $headers = array(), $body = null, $username = null, $password = null)
|
|
|
|
|
{
|
|
|
|
|
@@ -405,6 +416,8 @@ class Request
|
|
|
|
|
CURLOPT_HTTPHEADER => self::getFormattedHeaders($headers),
|
|
|
|
|
CURLOPT_HEADER => true,
|
|
|
|
|
CURLOPT_SSL_VERIFYPEER => self::$verifyPeer,
|
|
|
|
|
//CURLOPT_SSL_VERIFYHOST accepts only 0 (false) or 2 (true). Future versions of libcurl will treat values 1 and 2 as equals
|
|
|
|
|
CURLOPT_SSL_VERIFYHOST => self::$verifyHost === false ? 0 : 2,
|
|
|
|
|
// If an empty string, '', is set, a header containing all supported encoding types is sent
|
|
|
|
|
CURLOPT_ENCODING => ''
|
|
|
|
|
));
|
|
|
|
|
|