Web services 如何使用php从Web服务获取数据?
我想从这个web服务获得响应 web_server.php文件Web services 如何使用php从Web服务获取数据?,web-services,webservice-client,Web Services,Webservice Client,我想从这个web服务获得响应 web_server.php文件 <?php function celcius($temp){ ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache $wsdl_path = "http://www.w3schools.com/webservices/tempconvert.asmx"; $client = new SoapClient($wsdl_path, a
<?php
function celcius($temp){
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$wsdl_path = "http://www.w3schools.com/webservices/tempconvert.asmx";
$client = new SoapClient($wsdl_path, array('trace' => 1)); //creating a SOAP Client
try {
$result = $client->CelsiusToFahrenheit(array("Celsius" => $temp));
$sxml = $client->__getLastResponse();
$xml = simplexml_load_string($sxml);
echo $xml;
$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$ret_values = array("Fahrenheit"=>string);
return $ret_values;
}
catch (SoapFault $exception) {
echo $exception;
}
}
?>
<?php
temp_converter();
function temp_converter(){
include 'web_server.php';
$temprature = Array();
echo celcius("27");
$temprature = celcius("27");
try{
if($temprature['STATUS'] == 1){
echo json_encode($temprature);
}
else{
$temprature = array("Fahrenheit" => "");
echo json_encode($temprature);
exit();
}
}
catch(Exception $e){
echo $e->getMessage();
}
}
?>
\uuu getLastResponse();
$xml=simplexml\u load\u字符串($sxml);
echo$xml;
$xml->registerXPathNamespace('soap','http://schemas.xmlsoap.org/soap/envelope/');
$ret_values=数组(“华氏”=>字符串);
返回$ret_值;
}
catch(SoapFault$异常){
echo$例外;
}
}
?>
temp_websrvc.php文件
<?php
function celcius($temp){
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$wsdl_path = "http://www.w3schools.com/webservices/tempconvert.asmx";
$client = new SoapClient($wsdl_path, array('trace' => 1)); //creating a SOAP Client
try {
$result = $client->CelsiusToFahrenheit(array("Celsius" => $temp));
$sxml = $client->__getLastResponse();
$xml = simplexml_load_string($sxml);
echo $xml;
$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$ret_values = array("Fahrenheit"=>string);
return $ret_values;
}
catch (SoapFault $exception) {
echo $exception;
}
}
?>
<?php
temp_converter();
function temp_converter(){
include 'web_server.php';
$temprature = Array();
echo celcius("27");
$temprature = celcius("27");
try{
if($temprature['STATUS'] == 1){
echo json_encode($temprature);
}
else{
$temprature = array("Fahrenheit" => "");
echo json_encode($temprature);
exit();
}
}
catch(Exception $e){
echo $e->getMessage();
}
}
?>
我已经有一段时间没有使用SoapClient了,但尝试将摄氏度函数更改为:
function celsius($temp) {
try {
$result = $client->CelsiusToFahrenheit(array("Celsius" => $temp));
return $result;
}
catch (SoapFault $exception) {
echo $exception;
}
$farenheitTemperature = 100; //for example
$celsius = celsius($farenheitTemperature);
你真正的问题是什么?发生了什么事?你预计会发生什么?你已经做了什么调试?