[英]How to create an arbitrary SOAP request using PHP?
我在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'
);
?>
毕竟找到了解决方案。
<?php
$client = new SoapClient('http://www.example.com/services/RecipeCouponAPI11.asmx?wsdl');
$header = new SoapHeader(
'http://www.example.com/services/',
'RCAuthenticator',
array(
'UserName' => 'username',
'Password' => 'password'
)
);
$client->__setSoapHeaders($header);
$response = $client->GetCouponAll(array('campaignCode' => ''));
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.