使用 PHP 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():参数无效。命名空间无效。在 /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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我需要类似的东西,并且能够使用 XSD_ANYXML SoapVar 来实现此目的:
这导致:
I needed something similar and was able to use an XSD_ANYXML SoapVar to achieve this:
This resulted in:
在您的示例中,您仅创建一个 SoapHeader 条目(具有命名空间,但名为“null”)。您想要的结果包含两个单独的标头条目(没有命名空间),因此您可以尝试:
然后将
$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:
You'd then pass the
$headers
array to the soap call (either directly, or upfront via__setSoapHeaders
).