使用 PHP Soap 函数自定义标头

发布于 2024-08-26 21:09:38 字数 1397 浏览 3 评论 0原文

我在获取自定义肥皂头以与 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():参数无效。命名空间无效。在 /usr/home/deepesh/SoapCalls/deepesh7.php 第 29 行

I am having a problem getting a custom soap header to work with PHP5. Can anybody guide me please.

What I require is something like this

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

What I get is :

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

I would like to remove the namespace tags.
The code I use to get this is:

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 doesn't seem to pass.. with 'null' I still get name space as in second example.. how to exclude this NS... thanks for your help in advance..

$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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

儭儭莪哋寶赑 2024-09-02 21:09:38

我需要类似的东西,并且能够使用 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>

I needed something similar and was able to use an XSD_ANYXML SoapVar to achieve this:

    $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 );

This resulted in:

<SOAP-ENV:Header>
   <username>12345</username>
   <password>12</password>
</SOAP-ENV:Header>
烟火散人牵绊 2024-09-02 21:09:38

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

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

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

In your example, you are creating only one SoapHeader entry (with namespace, but named 'null'). Your desired result contains two separate header entries (without namespace), so you might try:

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

You'd then pass the $headers array to the soap call (either directly, or upfront via __setSoapHeaders).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文