Getting Response Body using Zend_http_Client

不羁的心 提交于 2019-12-10 20:57:31

问题


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 ();


来源:https://stackoverflow.com/questions/3350494/getting-response-body-using-zend-http-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!