Getting response body using Zend_http_Client

I successfully call the REST API with the following code

$client = new Zend_Http_Client();
$client->setMethod(Zend_Http_Client::POST);
$client->setUri('http://www.example.com/api/type/');
$client->setParameterPost(array(
    'useremail'  => '******@*****.***',
    'apikey'   => 'secretkey',
    'description' => 'TEST WEB API',
    'amount'   => '5000.00'
    ));

However, I would like to get both the header value - (201) and the Response Body , which are returned after execution.

How do I proceed?

+3
source share
2 answers

I assume that you are actually executing the request through:

$response = $client->request();

At this point, all you need is in the $ response object,

//Dump headers
print_r($response->headers);

//Dump body
echo $response->getBody();

See the Zend_Http_Response docs at:

http://framework.zend.com/apidoc/1.10/

for more methods available.

+5
source

this should work ...

 $client->setUri ( $image_source_urls );
 $response = $client->request ( 'GET' );
 $folder_content = $response->getBody ();
+1
source

Source: https://habr.com/ru/post/1756866/


All Articles