我试图发送SoapHeader。当我尝试使用帮助方法“ __getLastRequestHeaders()”来获取最后一个请求标头时,返回NULL。
我已经阅读了一些文档,因此https://www.php.net/manual/en/soapclient.soapclient.php的所有有关SoapClint,SoapHeader和长时间的信息都可以在Internet上搜索。
我需要获取它的标题。
<env:Header><ns2:MessageID>urn:uuid:df18b300-909e-4f50-b7c7-50247b4b1c0c</ns2:MessageID>
<ns2:ReplyTo>
<ns2:Address>http://www.w3.org/2005/08/addressing/anonymous</ns2:Address>
</ns2:ReplyTo>
<ns2:To s:mustUnderstand="1" xmlns:s="s">https://ufot.rgs.ru/Osago2Service.svc?singlewsdl</ns2:To>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:s="s">
<o:UsernameToken xmlns:u="u">
<o:Username>username</o:Username>
<o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</o:Password>
</o:UsernameToken>
</o:Security>
<ns2:Action>http://tempuri.org/IOsagoService/Calculate</ns2:Action></env:Header>
这是我尝试发送标头的方式。
ini_set('soap.wsdl_cache_enabled', 0);
ini_set('soap.wsdl_cache_ttl',0);
ini_set('default_socket_timeout', 300);
$data = [];
$ns = 'https://ufot.rgs.ru:443/Osago2Service.svc';
$headerBody = new SoapVar([
'UsernameToken'=>[
'Username'=>'*******',
'Password'=>'******',
]
], SOAP_ENC_OBJECT);
//$header = new SoapHeader($ns, 'Security', $headerBody);
//$soapClient->__setSoapHeaders([$header]);
try {
$soapClient = new SoapClient(null, ['location'=>'https://ufot.rgs.ru:443/', 'uri'=>'https://ufot.rgs.ru/Osago2Service.svc?singlewsdl']);
$result = $soapClient->__soapCall('Calculate', null, null, new SoapHeader($ns, 'Security', $headerBody, false));
var_dump($soapClient->__getLastRequestHeaders());
} catch (`enter code here`Exception $e) {
echo $e->getMessage().'('.$e->getCode().') in file '. $e->getFile().' on line '. $e->getLine();
}
ini_set('soap.wsdl_cache_enabled', 0);
ini_set('soap.wsdl_cache_ttl',0);
ini_set('default_socket_timeout', 300);
$data = [];
$ns = 'https://ufot.rgs.ru:443/Osago2Service.svc';
$headerBody = new SoapVar([
'UsernameToken'=>[
'Username'=>'*******',
'Password'=>'******',
]
], SOAP_ENC_OBJECT);
//$header = new SoapHeader($ns, 'Security', $headerBody);
//$soapClient->__setSoapHeaders([$header]);
try {
$soapClient = new SoapClient(null, ['location'=>'https://ufot.rgs.ru:443/', 'uri'=>'https://ufot.rgs.ru/Osago2Service.svc?singlewsdl']);
$result = $soapClient->__soapCall('Calculate', null, null, new SoapHeader($ns, 'Security', $headerBody, false));
var_dump($soapClient->__getLastRequestHeaders());
} catch (`enter code here`Exception $e) {
echo $e->getMessage().'('.$e->getCode().') in file '. $e->getFile().' on line '. $e->getLine();
}
var_dump返回Null,我需要它返回标头