使用PHP soap函数的自定义标题

前端之家收集整理的这篇文章主要介绍了使用PHP soap函数的自定义标题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在使用自定义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);

Fatal error: SoapHeader::SoapHeader(): Invalid parameters. Invalid namespace. in /usr/home/deepesh/SoapCalls/deepesh7.PHP on line 29

我需要类似的东西,并能够使用XSD_ANYXML SoapVar来实现这一目标:
$auth = "<username>$username</username>";
    $auth .= "<password>$password</password>";
    $auth_block = new SoapVar( $auth,XSD_ANYXML,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>

猜你在找的PHP相关文章