Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ec5828c8aa | ||
|
|
0293eb258c | ||
|
|
a1ed45be55 | ||
|
|
8da79e7898 | ||
|
|
217b436124 | ||
|
|
d508bd9628 | ||
|
|
7116894dad |
17
README.md
17
README.md
@@ -22,6 +22,7 @@ Unirest is a set of lightweight HTTP libraries available in [multiple languages]
|
|||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- [cURL](http://php.net/manual/en/book.curl.php)
|
- [cURL](http://php.net/manual/en/book.curl.php)
|
||||||
|
- PHP 5.4+
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -156,6 +157,22 @@ $response = Unirest\Request::get("http://mockbin.com/request", null, null, "user
|
|||||||
|
|
||||||
**This has been deprecated, and will be completely removed in `v.3.0.0` please use the `Unirest\Request::auth()` method instead**
|
**This has been deprecated, and will be completely removed in `v.3.0.0` please use the `Unirest\Request::auth()` method instead**
|
||||||
|
|
||||||
|
### Cookies
|
||||||
|
|
||||||
|
Set a cookie string to specify the contents of a cookie header. Multiple cookies are separated with a semicolon followed by a space (e.g., "fruit=apple; colour=red")
|
||||||
|
|
||||||
|
```php
|
||||||
|
Unirest\Request::cookie($cookie)
|
||||||
|
```
|
||||||
|
|
||||||
|
Set a cookie file path for enabling cookie reading and storing cookies across multiple sequence of requests.
|
||||||
|
|
||||||
|
```php
|
||||||
|
Unirest\Request::cookieFile($cookieFile)
|
||||||
|
```
|
||||||
|
|
||||||
|
`$cookieFile` must be a correct path with write permission.
|
||||||
|
|
||||||
### Request Object
|
### Request Object
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ use Unirest\Response;
|
|||||||
|
|
||||||
class Request
|
class Request
|
||||||
{
|
{
|
||||||
|
private static $cookie = null;
|
||||||
|
private static $cookieFile = null;
|
||||||
|
private static $defaultHeaders = array();
|
||||||
private static $handle = null;
|
private static $handle = null;
|
||||||
private static $jsonOpts = array();
|
private static $jsonOpts = array();
|
||||||
private static $verifyPeer = true;
|
|
||||||
private static $socketTimeout = null;
|
private static $socketTimeout = null;
|
||||||
private static $defaultHeaders = array();
|
private static $verifyPeer = true;
|
||||||
|
|
||||||
private static $auth = array (
|
private static $auth = array (
|
||||||
'user' => '',
|
'user' => '',
|
||||||
@@ -102,6 +104,28 @@ class Request
|
|||||||
return self::defaultHeader('X-Mashape-Key', $key);
|
return self::defaultHeader('X-Mashape-Key', $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a coockie string for enabling coockie handling
|
||||||
|
*
|
||||||
|
* @param string $cookie
|
||||||
|
*/
|
||||||
|
public static function cookie($cookie)
|
||||||
|
{
|
||||||
|
self::$cookie = $cookie;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a coockie file path for enabling coockie handling
|
||||||
|
*
|
||||||
|
* $cookieFile must be a correct path with write permission
|
||||||
|
*
|
||||||
|
* @param string $cookieFile - path to file for saving cookie
|
||||||
|
*/
|
||||||
|
public static function cookieFile($cookieFile)
|
||||||
|
{
|
||||||
|
self::$cookieFile = $cookieFile;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all the default headers
|
* Clear all the default headers
|
||||||
*/
|
*/
|
||||||
@@ -360,6 +384,15 @@ class Request
|
|||||||
curl_setopt(self::$handle, CURLOPT_TIMEOUT, self::$socketTimeout);
|
curl_setopt(self::$handle, CURLOPT_TIMEOUT, self::$socketTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (self::$cookie) {
|
||||||
|
curl_setopt(self::$handle, CURLOPT_COOKIE, self::$cookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self::$cookieFile) {
|
||||||
|
curl_setopt(self::$handle, CURLOPT_COOKIEFILE, self::$cookieFile);
|
||||||
|
curl_setopt(self::$handle, CURLOPT_COOKIEJAR, self::$cookieFile);
|
||||||
|
}
|
||||||
|
|
||||||
// supporting deprecated http auth method
|
// supporting deprecated http auth method
|
||||||
if (!empty($username)) {
|
if (!empty($username)) {
|
||||||
curl_setopt_array(self::$handle, array(
|
curl_setopt_array(self::$handle, array(
|
||||||
|
|||||||
Reference in New Issue
Block a user