|
|
Zend Framework 2 Documentation (Manual) | |
|
File: /_sources/modules/zend.http.client-static.txt
Size: | 1938 |
Storage flags: | no_autoload,compress/gzip (39%) |
.. _zend.http.client-static:
HTTP Client - Static Usage
==========================
.. _zend.http.client-static.intro:
Overview
--------
The ``Zend\Http`` component also provides ``Zend\Http\ClientStatic``, a static
HTTP client which exposes a simplified API for quickly performing GET and POST
operations:
.. _zend.http.client-static.quick-start:
Quick Start
-----------
.. code-block:: php
:linenos:
use Zend\Http\ClientStatic;
// Simple GET request
$response = ClientStatic::get('http://example.org');
// More complex GET request, specifying query string 'foo=bar' and adding a
// custom header to request JSON data be returned (Accept: application/json)
$response = ClientStatic::get(
'http://example.org',
array('foo' => 'bar'),
array('Accept' => 'application/json')
);
// We can also do a POST request using the same format. Here we POST
// login credentials (username/password) to a login page:
$response = ClientStatic::post('https://example.org/login.php', array(
'username' => 'foo',
'password' => 'bar',
));
Available Methods
-----------------
.. _zend.http.client-static.methods.get:
**get**
``get(string $url, array $query = array(), array $headers = array(), mixed $body = null, $clientOptions = null)``
Perform an HTTP ``GET`` request using the provided URL, query string variables, headers
and request body. The fifth parameter can be used to pass configuration options to the
HTTP Client instance.
Returns Zend\\Http\\Response
.. _zend.http.client-static.methods.post:
**post**
``post(string $url, array $params, array $headers = array(), mixed $body = null, $clientOptions = null)``
Perform an HTTP ``POST`` request using the provided URL, parameters, headers
and request body. The fifth parameter can be used to pass configuration options to the
HTTP Client instance.
Returns Zend\\Http\\Response
For more information about the PHK package format: http://phk.tekwire.net