如何给soap添加header头 php

如何给soap添加header头 php,第1张

使用php 设置soapHeader时要如下进行,不然发出去的包会变成类似“<item><key>user</key><value>23107720</value></item>”的格式:  $auth_header = array( 'user'=>$key, 'password'=>$pwd ) // 下面的RequestSOAPHeader 对应 wsdl 定义里面的 <xsd:element name="RequestSOAPHeader">..... $authvalues = new SoapVar($auth_header, SOAP_ENC_OBJECT,"RequestSOAPHeader",$uri)$header = new SoapHeader($uri, 'RequestSOAPHeader', $authvalues)$api = new SoapClient(null,$options)$api->__setSoapHeaders(array($header))不明白的话可以去后盾人看看相关的教学视频。

添加SOAP头之前的请求格式如下:

[html] view plaincopy

<?xml version='1.0' encoding='utf-8'?>

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">

<soapenv:Body>

<ns1:add xmlns:ns1="http://sean.com">

<ns1:x>1</ns1:x>

<ns1:y>1</ns1:y>

</ns1:add>

</soapenv:Body>

</soapenv:Envelope>

添加SOAP头之后的请求格式如下:

[html] view plaincopy

<?xml version='1.0' encoding='utf-8'?>

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">

<soapenv:Header>

<sean:Security xmlns:sean="http://sean.com">

<sean:Token>

<sean:Username>root</sean:Username>

<sean:Password Type="PasswordT


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/11170675.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存