Home >Backend Development >PHP Tutorial >nusoap如何封装请求头
用php请求java的webservice接口,对方考虑到安全因素,需要在请求头包含一个验证信息
考虑到安全因素,因此需要WS的客户端在调用服务的时候,请求头需要包含一个验证信息,否则服务将不可访问。实现方式为注册一个CallbackHandler,进行identifier的验证。
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);
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
今天终于弄好了,我想以后应该也会有人有此疑惑的,顾贴出源码,省去我这几天所浪费的时间
$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);