【发布时间】:2020-04-02 23:18:48
【问题描述】:
我想从某个 url 检索响应,但该 URL 使用 xml 返回它的响应。有没有办法使用 Guzzle 检索此响应?在 Guzzle 5.3 中,我们可以轻松地做类似的事情
$response->xml()
因此这将解析 xml 内容。现在,当我尝试在 Guzzle 6.2 中使用相同的代码时,它不再工作了。下面是我的代码
$response = $client->get($this->url);
$resp = $response->xml();
但这不起作用。我也在下面尝试过
$response = $client->get($this->url);
$response = $response->getBody()->getContents();
$responseXml = simplexml_load_string($response);
if ($responseXml instanceof \SimpleXMLElement)
{
$key_value = (string)$responseXml->key_name;
return $key_value;
}
但这不起作用。关于如何检索 xml 数据的任何想法?
【问题讨论】:
-
你的错误是什么?
-
抱歉弄错了。将发布我的答案