我在 Laravel 项目中使用 php 库 SoapClient 来获取 Web 服务的信息,该服务有时会在其 xml 中返回此类响应:
�
当我使用 linux 控制台测试 web 服务时,我得到这个:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:SearchResponse xmlns:ns2="http://xxxxx"><return><CodigoError>009</CodigoError><Error>c�digo....</Error></return></ns2:SearchResponse></soap:Body></soap:Envelope>
这是我在控制台中使用的请求:
curl --request POST \
--url 'https://xxxxxxxxxxxxxxxxxxxxxx?wsdl' \
--header 'Content-Type: text/xml' \
--data '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tns="http://xxxxxxxxxxxxxxxxxxxxxx"
>
<soap:Body>
<tns:Search>
<code>123</code>
.....
</tns:Search>
</soap:Body>
</soap:Envelope>'
在 php 中我使用这个:
$options = [
'trace' => true,
'cache_wsdl' => WSDL_CACHE_NONE,
'connection_timeout' => 30
];
$client = new SoapClient('https://xxxxxxxxxxx?WSDL', $options);
$params = [
'code'=>'123'
];
$result = $client->Search($params);
return response()->json($result);
它正在返回这个:
{
"return": []
}
我能做什么?