【问题标题】:Custom header using PHP soap functions使用 PHP 肥皂函数的自定义标头
【发布时间】:2011-02-01 04:48:57
【问题描述】:

我在获取自定义soap 标头以使用PHP5 时遇到问题。谁能指导我。

我需要的是这样的

<SOAP-ENV:Header>
  <USER>myusername</USER>
  <PASSWORD>mypassword</PASSWORD>
</SOAP-ENV:Header>  

我得到的是:

<SOAP-ENV:Header>
  <ns2:null>
    <USER>myusername</USER>
    <PASSWORD>mypassword</PASSWORD>
  </ns2:null>
</SOAP-ENV:Header> 

我想删除命名空间标签。 我用来得到这个的代码是:

class Authstuff {
  public $USER;
  public $PASSWORD;

  public function __construct($user, $pass) {
    $this->USER = $user;
    $this->PASSWORD = $pass;
  }
} 

$auth = new Authstuff('myusername', 'mypassword');
$param = array('Authstuff' => $auth);
$authvalues = new SoapVar($auth,SOAP_ENC_OBJECT);

$header = new SoapHeader('http://soapinterop.org/echoheader/',"null",$authvalues);

Null 似乎没有通过.. 'null' 我仍然像第二个示例一样获得名称空间.. 如何排除这个 NS...提前感谢您的帮助..

$headers = array();
$headers[] = new SoapHeader(null, 'USER', $username);
$headers[] = new SoapHeader(null, 'PASSWORD', $password);

$client->__setSoapHeaders($headers);
try {
    $result = $client->getAvailableLicensedDNCount('ASX01');
    print_r($result);

致命错误:SoapHeader::SoapHeader():无效参数。无效的命名空间。在第 29 行的 /usr/home/deepesh/SoapCalls/deepesh7.php 中

【问题讨论】:

    标签: soap soap-client php


    【解决方案1】:

    我需要类似的东西,并且能够使用 XSD_ANYXML SoapVar 来实现:

        $auth = "<username>$username</username>";
        $auth .= "<password>$password</password>";
        $auth_block = new SoapVar( $auth, XSD_ANYXML, NULL, NULL, NULL, NULL );
    
        $header = new SoapHeader( 'http://schemas.xmlsoap.org/soap/envelope/', 'Header', $auth_block );
        $soap_client->__setSoapHeaders( $header );
    

    这导致:

    <SOAP-ENV:Header>
       <username>12345</username>
       <password>12</password>
    </SOAP-ENV:Header>
    

    【讨论】:

      【解决方案2】:

      在您的示例中,您只创建了一个 SoapHeader 条目(具有命名空间,但名为“null”)。您想要的结果包含两个单独的标题条目(没有命名空间),因此您可以尝试:

      $headers = array();
      $headers[] = new SoapHeader(NULL, 'USER', $auth->USER);
      $headers[] = new SoapHeader(NULL, 'PASSWORD', $auth->PASSWORD);
      

      然后您将$headers 数组传递给soap 调用(直接或通过__setSoapHeaders 预先)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多