|
| 1 | +# HTTP Client - Static Usage |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The `Zend\Http` component also provides `Zend\Http\ClientStatic`, a static HTTP client which exposes |
| 6 | +a simplified API for quickly performing GET and POST operations: |
| 7 | + |
| 8 | +## Quick Start |
| 9 | + |
| 10 | +```php |
| 11 | +use Zend\Http\ClientStatic; |
| 12 | + |
| 13 | +// Simple GET request |
| 14 | +$response = ClientStatic::get('http://example.org'); |
| 15 | + |
| 16 | +// More complex GET request, specifying query string 'foo=bar' and adding a |
| 17 | +// custom header to request JSON data be returned (Accept: application/json) |
| 18 | +$response = ClientStatic::get( |
| 19 | + 'http://example.org', |
| 20 | + array('foo' => 'bar'), |
| 21 | + array('Accept' => 'application/json') |
| 22 | +); |
| 23 | + |
| 24 | +// We can also do a POST request using the same format. Here we POST |
| 25 | +// login credentials (username/password) to a login page: |
| 26 | +$response = ClientStatic::post('https://example.org/login.php', array( |
| 27 | + 'username' => 'foo', |
| 28 | + 'password' => 'bar', |
| 29 | +)); |
| 30 | +``` |
| 31 | + |
| 32 | +## Available Methods |
| 33 | + |
| 34 | +**get** |
| 35 | +`get(string $url, array $query = array(), array $headers = array(), mixed $body = null, |
| 36 | +$clientOptions = null)` |
| 37 | + |
| 38 | +Perform an HTTP `GET` request using the provided URL, query string variables, headers and request |
| 39 | +body. The fifth parameter can be used to pass configuration options to the HTTP Client instance. |
| 40 | + |
| 41 | +Returns Zend\\Http\\Response |
| 42 | + |
| 43 | +<!-- --> |
| 44 | + |
| 45 | +**post** |
| 46 | +`post(string $url, array $params, array $headers = array(), mixed $body = null, $clientOptions = |
| 47 | +null)` |
| 48 | + |
| 49 | +Perform an HTTP `POST` request using the provided URL, parameters, headers and request body. The |
| 50 | +fifth parameter can be used to pass configuration options to the HTTP Client instance. |
| 51 | + |
| 52 | +Returns Zend\\Http\\Response |
| 53 | + |
| 54 | + |
0 commit comments