php 如何在php中使用soap发送xml请求?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6535353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to send xml request using soap in php?
提问by Hearaman
I am working on new project, for this project i have to use SOAP. I am new to this SOAP. I red my project documentation. In that documentation it has WSDL and XML request. By using boath WSDL and XML request how can i send XML request. Bellow i am writing WSDL and XML request. Please help me.
我正在开发新项目,对于这个项目,我必须使用 SOAP。我是这个 SOAP 的新手。我红了我的项目文档。在该文档中,它具有 WSDL 和 XML 请求。通过使用boath WSDL 和XML 请求,我如何发送XML 请求。波纹管我正在编写 WSDL 和 XML 请求。请帮我。
Thankyou.
谢谢你。
WSDL:
WSDL:
http://acceptance.travelstreet.com/hotelsv3/components/hotels_ws.cfc?wsdl
http://acceptance.travelstreet.com/hotelsv3/components/hotels_ws.cfc?wsdl
XML REQUEST:
XML 请求:
<?xml version="1.0" encoding="utf-8"?>
<OTA_HotelAvailRQ Version="1.0">
<POS>
<Source>
<UniqueId Id="username:password" />
</Source>
</POS>
<AvailRequestSegments>
<AvailRequestSegment>
<StayDateRange End="2011-08-15" Start="2011-08-14" />
<RoomStayCandidates>
<RoomStayCandidate Quantity="1">
<GuestCounts>
<GuestCount AgeQualifyingCode="10" Count="1" />
</GuestCounts>
</RoomStayCandidate>
</RoomStayCandidates>
<HotelSearchCriteria>
<Criterion>
<HotelRef Destination="East London, South Africa" CityCode="" CountryCode="" HotelName="" MinHotelRating="1"/>
<SearchCurrency>EUR</SearchCurrency>
<AdditionalInfo Value="1" />
<Language>EN</Language>
</Criterion>
</HotelSearchCriteria>
</AvailRequestSegment>
</AvailRequestSegments>
</OTA_HotelAvailRQ>
回答by Spudley
I suggest you read up about PHP's SoapClient. There are lots of good examples in the PHP manual.
我建议您阅读有关PHP 的 SoapClient。PHP手册中有很多很好的例子。
To get you started, create the object:
为了让您开始,请创建对象:
$client = new SoapClient('http://www.example.com/end_point.wsdl');
Then call the method:
然后调用方法:
$result = $client->SomeFunction($data);
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.
其中SomeFunction
是您要在服务上调用的方法名称,$data 是一个 PHP 数组,表示您要发送的 XML 数据结构。
Hope that helps.
希望有帮助。
[EDIT] Just to clarify in light of the OP's further questions:
[编辑] 只是为了澄清 OP 的进一步问题:
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.
使用 PHP SOAPClient 时,您不需要创建实际的 XML 代码。您需要将数据放入一个 PHP 数组中,SOAPClient 会为您将其转换为 XML。数组键应以 XML 元素名称命名,数组值是元素值。对嵌套的 XML 元素使用嵌套数组。
回答by Marin Vartan
For attributes, you must call SoapVar with XSD_ANYXML http://php.net
对于属性,您必须使用 XSD_ANYXML http://php.net调用 SoapVar