Merge pull request #77 from cristianp6/master
Fixed "Undefined variable: ch" and add cookie string support
This commit is contained in:
@@ -159,6 +159,12 @@ $response = Unirest\Request::get("http://mockbin.com/request", null, null, "user
|
|||||||
|
|
||||||
### Cookies
|
### 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.
|
Set a cookie file path for enabling cookie reading and storing cookies across multiple sequence of requests.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use Unirest\Response;
|
|||||||
|
|
||||||
class Request
|
class Request
|
||||||
{
|
{
|
||||||
|
private static $cookie = null;
|
||||||
private static $cookieFile = null;
|
private static $cookieFile = null;
|
||||||
private static $defaultHeaders = array();
|
private static $defaultHeaders = array();
|
||||||
private static $handle = null;
|
private static $handle = null;
|
||||||
@@ -103,6 +104,16 @@ 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
|
* Set a coockie file path for enabling coockie handling
|
||||||
*
|
*
|
||||||
@@ -373,9 +384,13 @@ 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) {
|
if (self::$cookieFile) {
|
||||||
curl_setopt($ch, CURLOPT_COOKIEFILE, self::$cookieFile);
|
curl_setopt(self::$handle, CURLOPT_COOKIEFILE, self::$cookieFile);
|
||||||
curl_setopt($ch, CURLOPT_COOKIEJAR, self::$cookieFile);
|
curl_setopt(self::$handle, CURLOPT_COOKIEJAR, self::$cookieFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// supporting deprecated http auth method
|
// supporting deprecated http auth method
|
||||||
|
|||||||
Reference in New Issue
Block a user