使用 Zend_http_Client 获取响应正文 [英] Getting Response Body using Zend_http_Client
本文介绍了使用 Zend_http_Client 获取响应正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码成功调用了 REST API
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'
));
但是我想同时获得执行后返回的 header value-(201) 和 Response Body.
However I would like to get both the header value-(201) and Response Body that are returned after the execution.
我该如何处理?
推荐答案
我假设您实际上是通过以下方式执行请求:
I am assuming that you're actually executing the request via:
$response = $client->request();
此时您需要的只是 $response 对象,
At that point all you need is in the $response object,
//Dump headers
print_r($response->headers);
//Dump body
echo $response->getBody();
参考 Zend_Http_Response 文档:
Refer to the Zend_Http_Response docs at:
http://framework.zend.com/apidoc/1.10/
了解更多可用的方法.
这篇关于使用 Zend_http_Client 获取响应正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文