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