簡體   English   中英

如何使用PHP創建任意SOAP請求?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM