折雨的天空
PHP的soapheader问题
2019-2-13 我好笨


PHP写的服务端,如果通过header验证需要注意一下



soapui工具里添加的header是放在$_SERVER数组中的。



而PHP的soapheader添加的,是放在soap原始请求中的,需要通过获取

MessageServer::soaputils_autoFindSoapRequest();

原始请求来取得。







部分服务端解析:







$username=isset($_SERVER['HTTP_USERNAME'])?$_SERVER['HTTP_USERNAME']:'';
$token=isset($_SERVER['HTTP_TOKEN'])?$_SERVER['HTTP_TOKEN']:'';
if($username=='' && $token=='')
{
//从原始请求中匹配
$region_msg=MessageServer::soaputils_autoFindSoapRequest();
preg_match('~<username>([^<]*)</username>~Uis',$region_msg,$u);
$_SERVER['HTTP_USERNAME']=$username=isset($u[1])?$u[1]:'';
preg_match('~<token>([^<]*)</token>~Uis',$region_msg,$t);
$_SERVER['HTTP_TOKEN']=$token=isset($t[1])?$t[1]:'';
}



PHP的客户端:







$client = new SoapClient('http://localhost/test.wsdl',array("trace"=>true,'soap_version' => SOAP_1_2));
$authvalues = new SoapVar(array('username'=>'aaaa','token'=>$token),SOAP_ENC_OBJECT);
$u = new SoapHeader('http://www.144d.com/','Authentication',$authvalues,false);
//添加soapheader
$client->__setSoapHeaders($u);

$result = $client->HIPMessageServer(array('action'=>"****", 'message'=>$xml));
echo $client->__getLastResponse();



发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容