【问题标题】:How to create an arbitrary SOAP request using PHP?如何使用 PHP 创建任意 SOAP 请求?
【发布时间】: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'
);
?>

【问题讨论】:

    标签: php soap wsdl client


    【解决方案1】:

    毕竟找到了解决办法。

    <?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' => ''));
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-03
      • 2011-11-01
      • 2014-07-24
      • 2019-08-16
      • 1970-01-01
      • 2017-03-09
      • 2014-05-05
      • 1970-01-01
      相关资源
      最近更新 更多