如何在 php 中发送 SOAP 请求
How to send SOAP requests in php
好的,所以我有一个 Python 服务器 运行ning 并且我一直在使用 "suds" 作为客户端,这非常简单,当我尝试 运行 PHP 中的类似代码,因为我是初学者,所以我很困惑?
from suds.client import Client
url = 'http://localhost:8080/FlightService?wsdl'
client = Client(url=url)
output = client.service.getFlightList("dxb","ksa")
print(output)
在 php 中有没有这样简单的东西,或者谁能告诉我一个示例代码 return 相同的结果?
考虑到服务器收到这个:
class Input(complextypes.ComplexType):
dpt = str
arr = str
和return航班列表
class flight(complextypes.ComplexType):
id = int
dpt = str
arr = str
price = float
date = str
tickets = int
这是网络服务:
@webservice(_params=Input,_returns=[flight])
def getFlightList(self, input):
我的 PHP 细分:
<?php
$url = 'http://172.27.130.98:8080/FlightService?wsdl';
$client = new SoapClient($url);
echo("Hello!");
$result = $client->bookFlight("dxb","ksa");
$result2 = $client->handle();
echo($result);
echo($result2);
?>
PHP 错误:
Fatal error: Uncaught SoapFault exception: [HTTP] Error Fetching http headers in C:\wamp\www\soap\soap.php:6 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://172.27.1...', 'http://172.27.1...', 1, 0) #1 C:\wamp\www\soap\soap.php(6): SoapClient->__call('getFlightList', Array) #2 C:\wamp\www\soap\soap.php(6): SoapClient->getFlightList('dxb', 'ksa') #3 {main} thrown in C:\wamp\www\soap\soap.php on line 6
异常信息:
SoapFault Object ( [message:protected] => Error Fetching http headers [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\wamp\www\soap\soap.php [line:protected] => 6 [trace:Exception:private] => Array ( [0] => Array ( [function] => __doRequest [class] => SoapClient [type] => -> [args] => Array ( [0] => ksa [1] => http://172.27.130.98:8080/FlightService [2] => http://172.27.130.98:8080/FlightService/getFlightList [3] => 1 [4] => 0 ) ) [1] => Array ( [file] => C:\wamp\www\soap\soap.php [line] => 6 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => getFlightList [1] => Array ( [0] => dxb [1] => ksa ) ) ) [2] => Array ( [file] => C:\wamp\www\soap\soap.php [line] => 6 [function] => getFlightList [class] => SoapClient [type] => -> [args] => Array ( [0] => dxb [1] => ksa ) ) ) [previous:Exception:private] => [faultstring] => Error Fetching http headers [faultcode] => HTTP [xdebug_message] => ( ! ) SoapFault: Error Fetching http headers in C:\wamp\www\soap\soap.php on line 6 Call Stack #TimeMemoryFunctionLocation 10.0006243160{main}( )..\soap.php:0 20.0758264872getFlightList ( )..\soap.php:6 30.0758265336__call ( )..\soap.php:6 )
这个解决方案对我有用,我用服务器端期望的变量名称实例化了一个关联数组,然后使用 var_dump 获得输出结果
<?php
$url = 'http://172.27.130.98:8080/FlightService?wsdl';
$client = new SoapClient($url);
echo("Hello!");
$trip["dpt"] = "dxb";
$trip["arr"] = "krt";
try{ $output = $client->getFlightList($trip);
}
catch(soapFault $e)
{
print_r($e);
}
var_dump($output);
?>
好的,所以我有一个 Python 服务器 运行ning 并且我一直在使用 "suds" 作为客户端,这非常简单,当我尝试 运行 PHP 中的类似代码,因为我是初学者,所以我很困惑?
from suds.client import Client
url = 'http://localhost:8080/FlightService?wsdl'
client = Client(url=url)
output = client.service.getFlightList("dxb","ksa")
print(output)
在 php 中有没有这样简单的东西,或者谁能告诉我一个示例代码 return 相同的结果?
考虑到服务器收到这个:
class Input(complextypes.ComplexType):
dpt = str
arr = str
和return航班列表
class flight(complextypes.ComplexType):
id = int
dpt = str
arr = str
price = float
date = str
tickets = int
这是网络服务:
@webservice(_params=Input,_returns=[flight])
def getFlightList(self, input):
我的 PHP 细分:
<?php
$url = 'http://172.27.130.98:8080/FlightService?wsdl';
$client = new SoapClient($url);
echo("Hello!");
$result = $client->bookFlight("dxb","ksa");
$result2 = $client->handle();
echo($result);
echo($result2);
?>
PHP 错误:
Fatal error: Uncaught SoapFault exception: [HTTP] Error Fetching http headers in C:\wamp\www\soap\soap.php:6 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://172.27.1...', 'http://172.27.1...', 1, 0) #1 C:\wamp\www\soap\soap.php(6): SoapClient->__call('getFlightList', Array) #2 C:\wamp\www\soap\soap.php(6): SoapClient->getFlightList('dxb', 'ksa') #3 {main} thrown in C:\wamp\www\soap\soap.php on line 6
异常信息:
SoapFault Object ( [message:protected] => Error Fetching http headers [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\wamp\www\soap\soap.php [line:protected] => 6 [trace:Exception:private] => Array ( [0] => Array ( [function] => __doRequest [class] => SoapClient [type] => -> [args] => Array ( [0] => ksa [1] => http://172.27.130.98:8080/FlightService [2] => http://172.27.130.98:8080/FlightService/getFlightList [3] => 1 [4] => 0 ) ) [1] => Array ( [file] => C:\wamp\www\soap\soap.php [line] => 6 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => getFlightList [1] => Array ( [0] => dxb [1] => ksa ) ) ) [2] => Array ( [file] => C:\wamp\www\soap\soap.php [line] => 6 [function] => getFlightList [class] => SoapClient [type] => -> [args] => Array ( [0] => dxb [1] => ksa ) ) ) [previous:Exception:private] => [faultstring] => Error Fetching http headers [faultcode] => HTTP [xdebug_message] => ( ! ) SoapFault: Error Fetching http headers in C:\wamp\www\soap\soap.php on line 6 Call Stack #TimeMemoryFunctionLocation 10.0006243160{main}( )..\soap.php:0 20.0758264872getFlightList ( )..\soap.php:6 30.0758265336__call ( )..\soap.php:6 )
这个解决方案对我有用,我用服务器端期望的变量名称实例化了一个关联数组,然后使用 var_dump 获得输出结果
<?php
$url = 'http://172.27.130.98:8080/FlightService?wsdl';
$client = new SoapClient($url);
echo("Hello!");
$trip["dpt"] = "dxb";
$trip["arr"] = "krt";
try{ $output = $client->getFlightList($trip);
}
catch(soapFault $e)
{
print_r($e);
}
var_dump($output);
?>