使用 PHP 的 SOAP 请求 [英] SOAP request with PHP
问题描述
有一个具有很多功能的网络服务(WSDL).我想用 PHP 调用这些函数之一.webservice 提供了一个文档,其中他们放置了一种格式,包括 header 和 xml,但我不知道我需要如何从 PHP 发送请求.我现在搜索了几个小时,但我根本不知道.
There is a webservice (WSDL) with a lot of functions. I want to call one of these functions with PHP. The webservice provides a documentation wherein they put a format including header and xml, but I have no idea how I need to send the request from PHP. I searched for a couple of hours now, and I simply don't know.
他们提供的示例请求:
POST POSTURL HTTP/1.1
Host: HOST
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "SOAPLOCATION"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Version xmlns="URL" />
</soap:Body>
</soap:Envelope>
也给出了我应该收到的响应,但我什至无法发送请求.
The response I should receive is also given, but I can't even send the request.
如何使用 PHP 发送请求以获取响应?我尝试了一些 PHP SoapClient 的东西,但我找不到易于阅读的教程或一些清晰的解释...
How do I send a request with PHP to get the response? I tried some PHP SoapClient things, but I can't find a easy to read tutorial or some clear explanation...
如果有人可以帮助我,那就太好了!
If anyone can help me, that would be great!
推荐答案
我有一个补充问题:
请求如下:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns="...">
<s:Body>
<Search>
<login>
<Wholesaler>...</Wholesaler>
<Username>...</Username>
<Password>...</Password>
</login>
<itemRequests>
<ItemRequest>
<ArticleId>int</ArticleId>
<SupplierId>int</SupplierId>
<QuantityRequested>int</QuantityRequested>
</ItemRequest>
</itemRequests>
</Search>
</s:Body>
</s:Envelope>
我需要发送两个 SoapHeaders:
There are two SoapHeaders I need to send:
Content-Type: text/xml; charset=utf-8
SOAPAction: URI
我知道服务提供者和操作标识符.
I do know the service provider and the action identifier.
如果我有以下变量
$service
$action
$request
$header
如何在 PHP 中发送请求?我试过
How can I send the request in PHP? I tried
$client = new SoapClient($service);
$result = $client->__doRequest($request, $service, $action);
但我似乎没有收到回复...
But I do not receive a response it seems...
响应应该是这样的:
Date: Thu, 09 Aug 2012 08:01:40 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Content-Length: 408
Cache-Control: private
Content-Type: text/xml; charset=utf-8
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SearchResponse xmlns="...">
<SearchResult>
<Wholesaler>...</Wholesaler>
<Username>...</Username>
<Error>false</Error>
<DateTime>2012-08-09T10:01:40.39125+02:00</DateTime>
<ItemResults />
</SearchResult>
</SearchResponse>
</s:Body>
</s:Envelope>
当我执行简单的 echo $result 时,屏幕保持白色并且在代码中没有可见的 XML.
When I do a simple echo $result, the screen stays white and in the code there is no XML visible.
这篇关于使用 PHP 的 SOAP 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!