d47fa5a33f578a6d0dc0a56b5319ad59d6bd9c99
[mdref/mdref-http] / http / Client / getResponse.md
1 # http\Client\Response http\Client::getResponse([http\Client\Request $request = NULL])
2
3 Retrieve the corresponding response of an already finished request, or the last received response if $request is not set.
4
5 > ***NOTE:***
6 > If $request is NULL, then the response is removed from the internal storage (stack-like operation).
7
8 ## Params:
9
10 * Optional http\Client\Request $request
11 The request to fetch the stored response for.
12
13 ## Returns:
14
15 * http\Client\Response, the stored response for the request, or the last that was received.
16 * NULL, if no more response was available to pop, when no $request was given.
17
18 ## Throws:
19
20 * http\Exception\InvalidArgumentException
21 * http\Exception\UnexpectedValueException
22
23 ## Example:
24
25 <?php
26 $client = new http\Client;
27 $client->enqueue(new http\Client\Request("GET", "http://php.net"));
28 $client->enqueue(new http\Client\Request("GET", "http://pecl.php.net"));
29 $client->enqueue(new http\Client\Request("GET", "http://pear.php.net"));
30 $client->send();
31
32 while ($res = $client->getResponse()) {
33 printf("%s returned %d\n", $res->getTransferInfo("effective_url"),
34 $res->getResponseCode());
35 }
36
37 Yields:
38
39 http://php.net/ returned 200
40 http://pecl.php.net/ returned 200
41 http://pear.php.net/ returned 200
42