【发布时间】:2010-04-16 14:14:44
【问题描述】:
我在 PHP 中遇到了与 SOAP 相关的问题。我正在尝试使用 Nusoap_client 类创建任意 SOAP 请求。包含标头的完整请求应如下例所示。当然占位符(字符串)应该替换为实际值。
POST /services/RecipeCouponAPI11.asmx HTTP/1.1
Host: example.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.example.com/services/GetCouponAll"
<?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:Header>
<RCAuthenticator xmlns="http://www.example.com/services/">
<UserName>string</UserName>
<Password>string</Password>
</RCAuthenticator>
</soap:Header>
<soap:Body>
<GetCouponAll xmlns="http://www.example.com/services/">
<campaignCode>string</campaignCode>
</GetCouponAll>
</soap:Body>
</soap:Envelope>
我尝试了以下 PHP 代码,但没有成功。似乎请求的格式不正确。关于如何让他工作的任何想法?
<?php
$client = new Nusoap_client('http://www.example.com/services/RecipeCouponAPI11.asmx');
$headers = new SoapHeader(
'http://www.example.com/services/',
'RCAuthenticator',
(object)array(
'UserName' => 'username',
'Password' => 'password'
),
false
);
$client->setHeaders(array($headers));
$response = $client->call(
'GetCouponAll',
array('campaignCode' => 'campaigncode'),
null,
'http://www.example.com/services/GetCouponAll'
);
?>
【问题讨论】: