mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Updating RestfulService
docs to explain how to set cURL options
see #3108
This commit is contained in:
parent
d01083cfce
commit
bef913aeb9
@ -137,6 +137,51 @@ If you want to bypass error handling on your sub-classes you could define that i
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
### Setting cURL options
|
||||||
|
|
||||||
|
Restful service uses cURL to make requests. There are various settings that can be defined on the cURL
|
||||||
|
request (see http://www.php.net/manual/en/function.curl-setopt.php) via the curl_setopts function.
|
||||||
|
|
||||||
|
There are two ways to define these for `RestfulService`; they can be global settings or per request settings.
|
||||||
|
|
||||||
|
It is important to note that your cURL options will be applied LAST and so take preference over any default
|
||||||
|
values that `RestfulService` sets (such as `CURLOPT_RETURNTRANSFER`) so changing these options may result
|
||||||
|
in unexpected behaviour or broken functionality.
|
||||||
|
|
||||||
|
|
||||||
|
#### Global cURL settings
|
||||||
|
|
||||||
|
To set global cURL settings you can update the `RestfulService` config via the Config system or YAML.
|
||||||
|
|
||||||
|
Here is an example to increase the HTTP Timeout globally. Insert this in your `_config.php` file:
|
||||||
|
|
||||||
|
```php
|
||||||
|
Config::inst()->update('RestfulService', 'default_curl_options', array(
|
||||||
|
CURLOPT_DNS_CACHE_TIMEOUT => 3600,
|
||||||
|
CURLOPT_CONNECTTIMEOUT => 10,
|
||||||
|
));
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Per request settings
|
||||||
|
|
||||||
|
When making a request using `RestfulService` one can also pass through an array of cURL options in the last
|
||||||
|
parameter in `RestfulService::request()`.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```php
|
||||||
|
|
||||||
|
//cURL options
|
||||||
|
$curlOptions = array(
|
||||||
|
CURLOPT_UNRESTRICTED_AUTH => true,
|
||||||
|
);
|
||||||
|
|
||||||
|
$service = new RestfulService('http://example.com/');
|
||||||
|
$service->request('service.json', 'GET', null, null, $curlOptions);
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
## Other Uses
|
## Other Uses
|
||||||
|
|
||||||
### How to use `[api:RestfulService]` to easily embed an RSS feed
|
### How to use `[api:RestfulService]` to easily embed an RSS feed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user