无法从 PHP Soapclient 获得响应
Cannot get response from PHP Soapclient
我正在尝试从发送 PHP SoapClient 请求中获取响应。我的理解是,在 Soap 中,class 存在于 Soap-server 上,并作为 Soapclient 的参数指定和获取,指出 wsdl 文件。
我正在使用以下 link 参考文献:
网络服务:
- https://swea.riksbank.se/sweaWS/docs/api/index.htm
- https://swea.riksbank.se/sweaWS/docs/api/call/getAnnualAverageExchangeRates.htm
PHP 肥皂客户端:
How to make a PHP SOAP call using the SoapClient class
我的代码:
<? php
$client = new SoapClient("https://swea.riksbank.se/sweaWS/wsdl/sweaWS_ssl.wsdl");
$params = array (
"year" => 2010,
"month" => 4
);
$response = $client->__soapCall('getAnnualAverageExchangeRates()', array($params));
var_dump($response);
错误信息:
PHP Fatal error: Uncaught Error: Class 'SoapClient' not found in /[path/Xxx.php:4
Stack trace:
#0 {main}
thrown in /path/Xxx.php on line 4
var_dump($response)
首先,您需要从 php.ini
启用 Soap 扩展。重新启动阿帕奇。然后检查 phpinfo()
以确保加载扩展。
$option = array('trace' => 1, 'keep_alive' => true,'connection_timeout' => 60);// add options here
$client = new SoapClient("https://swea.riksbank.se/sweaWS/wsdl/sweaWS_ssl.wsdl", $option);
$params = array (
"year" => 2010,
"month" => 4,
"languageid" => 1 //language id may differ.
);
// you can directly call function from wsdl.
$response = $client->getAnnualAverageExchangeRates(array($params));
var_dump($response);
我正在尝试从发送 PHP SoapClient 请求中获取响应。我的理解是,在 Soap 中,class 存在于 Soap-server 上,并作为 Soapclient 的参数指定和获取,指出 wsdl 文件。
我正在使用以下 link 参考文献:
网络服务:
- https://swea.riksbank.se/sweaWS/docs/api/index.htm
- https://swea.riksbank.se/sweaWS/docs/api/call/getAnnualAverageExchangeRates.htm
PHP 肥皂客户端:
How to make a PHP SOAP call using the SoapClient class
我的代码:
<? php
$client = new SoapClient("https://swea.riksbank.se/sweaWS/wsdl/sweaWS_ssl.wsdl");
$params = array (
"year" => 2010,
"month" => 4
);
$response = $client->__soapCall('getAnnualAverageExchangeRates()', array($params));
var_dump($response);
错误信息:
PHP Fatal error: Uncaught Error: Class 'SoapClient' not found in /[path/Xxx.php:4
Stack trace:
#0 {main}
thrown in /path/Xxx.php on line 4
var_dump($response)
首先,您需要从 php.ini
启用 Soap 扩展。重新启动阿帕奇。然后检查 phpinfo()
以确保加载扩展。
$option = array('trace' => 1, 'keep_alive' => true,'connection_timeout' => 60);// add options here
$client = new SoapClient("https://swea.riksbank.se/sweaWS/wsdl/sweaWS_ssl.wsdl", $option);
$params = array (
"year" => 2010,
"month" => 4,
"languageid" => 1 //language id may differ.
);
// you can directly call function from wsdl.
$response = $client->getAnnualAverageExchangeRates(array($params));
var_dump($response);