Getting Response Body using Zend_http_Client

2019-07-02 17:26发布

问题:

I am succesfully calling a 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 Response Body that are returned after the execution.

How do I proceed with that?

回答1:

I am assuming that you're actually executing the request via:

$response = $client->request();

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

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

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

Refer to the Zend_Http_Response docs at:

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

for more methods that are available.



回答2:

this should work...

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