Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e11c54d29c | ||
|
|
a3312a0ecd | ||
|
|
fde6f41733 | ||
|
|
75258a2024 | ||
|
|
b330685820 | ||
|
|
2f7aea9f63 | ||
|
|
f04b42e75e | ||
|
|
32c1a9fef0 | ||
|
|
2b5b349036 | ||
|
|
1017f14ef5 | ||
|
|
99c6975f23 | ||
|
|
f257217434 | ||
|
|
c9c0a85250 | ||
|
|
3e375515fe | ||
|
|
b6fb76ce12 | ||
|
|
5926846300 | ||
|
|
feae18f980 |
@@ -26,3 +26,11 @@ matrix:
|
||||
fast_finish: true
|
||||
allow_failures:
|
||||
- php: hhvm
|
||||
|
||||
notifications:
|
||||
webhooks:
|
||||
urls:
|
||||
- https://webhooks.gitter.im/e/d4319553d0aecfd5b9ac
|
||||
on_success: always
|
||||
on_failure: always
|
||||
on_start: false
|
||||
|
||||
13
README.md
13
README.md
@@ -7,7 +7,11 @@
|
||||
[![Gitter][gitter-image]][gitter-url]
|
||||
[![License][packagist-license]][license-url]
|
||||
|
||||
Unirest is a set of lightweight HTTP libraries available in [multiple languages](http://unirest.io).
|
||||
![][unirest-logo]
|
||||
|
||||
|
||||
[Unirest](http://unirest.io) is a set of lightweight HTTP libraries available in multiple languages, built and maintained by [Mashape](https://github.com/Mashape), who also maintain the open-source API Gateway [Kong](https://github.com/Mashape/kong).
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
@@ -47,7 +51,7 @@ composer require mashape/unirest-php
|
||||
This will get you the latest version of the reporter and install it. If you do want the master, untagged, version you may use the command below:
|
||||
|
||||
```shell
|
||||
composer require mashape/php-test-reporter:@dev-master
|
||||
composer require mashape/php-test-reporter dev-master
|
||||
```
|
||||
|
||||
Composer installs autoloader at `./vendor/autoloader.php`. to include the library in your script, add:
|
||||
@@ -62,7 +66,7 @@ If you use Symfony2, autoloader has to be detected automatically.
|
||||
|
||||
### Install from source
|
||||
|
||||
Unirest-PHP requires PHP `v5.4+`. Download the PHP library from Github, then include `Unirest.php` in your script:
|
||||
Download the PHP library from Github, then include `Unirest.php` in your script:
|
||||
|
||||
```shell
|
||||
git clone git@github.com:Mashape/unirest-php.git
|
||||
@@ -336,6 +340,9 @@ Unirest\Request::getCurlHandle()
|
||||
|
||||
Made with ♥ from the [Mashape][mashape-url] team
|
||||
|
||||
[unirest-logo]: http://cl.ly/image/2P373Y090s2O/Image%202015-10-12%20at%209.48.06%20PM.png
|
||||
|
||||
|
||||
[mashape-url]: https://www.mashape.com/
|
||||
|
||||
[license-url]: https://github.com/Mashape/unirest-php/blob/master/LICENSE
|
||||
|
||||
37
src/Unirest/Request.php
Normal file → Executable file
37
src/Unirest/Request.php
Normal file → Executable file
@@ -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' => '',
|
||||
@@ -55,6 +56,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)
|
||||
{
|
||||
@@ -376,9 +387,6 @@ class Request
|
||||
{
|
||||
self::$handle = curl_init();
|
||||
|
||||
// start with default options
|
||||
curl_setopt_array(self::$handle, self::$curlOpts);
|
||||
|
||||
if ($method !== Method::GET) {
|
||||
curl_setopt(self::$handle, CURLOPT_CUSTOMREQUEST, $method);
|
||||
|
||||
@@ -405,9 +413,14 @@ 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 => ''
|
||||
));
|
||||
|
||||
// update options
|
||||
curl_setopt_array(self::$handle, self::$curlOpts);
|
||||
|
||||
if (self::$socketTimeout !== null) {
|
||||
curl_setopt(self::$handle, CURLOPT_TIMEOUT, self::$socketTimeout);
|
||||
|
||||
Reference in New Issue
Block a user