且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在php中使用soap发送xml请求?

更新时间:2022-06-08 06:36:20

我建议你阅读有关 PHP 的内容肥皂客户端.PHP 手册中有很多很好的例子.

I suggest you read up about PHP's SoapClient. There are lots of good examples in the PHP manual.

为了让您开始,请创建对象:

To get you started, create the object:

$client = new SoapClient('http://www.example.com/end_point.wsdl');

然后调用方法:

$result = $client->SomeFunction($data);

其中 SomeFunction 是您要在服务上调用的方法名称,$data 是一个 PHP 数组,表示您要发送的 XML 数据结构.

where SomeFunction is the method name you want to call on the service, and $data is a PHP array representing the XML data structure you want to send.

希望有所帮助.

只是为了根据 OP 的进一步问题进行澄清:

Just to clarify in light of the OP's further questions:

在使用 PHP SOAPClient 时,您不需要创建实际的 XML 代码.您需要将数据放入一个 PHP 数组中,SOAPClient 会为您将其转换为 XML.数组键应以 XML 元素名称命名,数组值是元素值.对嵌套的 XML 元素使用嵌套数组.

You don't need to create the actual XML code when using PHP SOAPClient. You need to put the data into a PHP array, and SOAPClient will convert it to XML for you. The array keys should be named for the XML element names, and the array values are the element values. Use nested arrays for nested XML elements.