Home > Backend Development > PHP Tutorial > nusoap如何封装请求头

nusoap如何封装请求头

WBOY
Release: 2016-06-23 14:01:49
Original
1241 people have browsed it

    用php请求java的webservice接口,对方考虑到安全因素,需要在请求头包含一个验证信息

考虑到安全因素,因此需要WS的客户端在调用服务的时候,请求头需要包含一个验证信息,否则服务将不可访问。实现方式为注册一个CallbackHandler,进行identifier的验证。
Copy after login



一直使用nusoap进行接口封装,但对于请求头验证还是第一次遇到,哪位大大能够指点下,不甚感激!!!


回复讨论(解决方案)

HTTP认证?

soapHeader

soapHeader这个是php扩展的,nosuap没有这个

soapHeader


把服务器上的soap开启后,重新了下代码

        $client = new SoapClient($url);        $soap_header = New SoapHeader($url, 'CallbackHandler', 'wsAdmin',FALSE, SOAP_ACTOR_NEXT);        $client->__setSoapHeaders(array($soap_header));        $info = $client->__soapCall('getClassStudent', array('userId' => 1));print_r($info);            
Copy after login


运行后,每次都报错

SoapFault exception: [ns1:InvalidSecurity] An error was discovered processing the header in /var/www/html/Exam/Lib/Action/Home/IndexAction.class.php:264 Stack trace: #0 
Copy after login

今天终于弄好了,我想以后应该也会有人有此疑惑的,顾贴出源码,省去我这几天所浪费的时间

$xml = '<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">                    <wsse:UsernameToken>                    <wsse:Username>admin</wsse:Username>                    <wsse:Password>PasswordText</wsse:Password>                    </wsse:UsernameToken>                    </wsse:Security>';$s = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'CallbackHandler', new SoapVar($xml, XSD_ANYXML), TRUE);$client = new SoapClient($wsdl);$client->__setSoapHeaders(array($s));print_r($client);
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template