flush
[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 response was found.
16
17 ## Example:
18
19 <?php
20 $client = new http\Client;
21 $client->enqueue(new http\Client\Request("GET", "http://php.net"));
22 $client->enqueue(new http\Client\Request("GET", "http://pecl.php.net"));
23 $client->enqueue(new http\Client\Request("GET", "http://pear.php.net"));
24 $client->send();
25
26 while ($res = $client->getResponse()) {
27 printf("%s returned %d\n", $res->getTransferInfo("effective_url"),
28 $res->getResponseCode());
29 }
30
31 Yields:
32
33 http://php.net/ returned 200
34 http://pecl.php.net/ returned 200
35 http://pear.php.net/ returned 200
36