问题
I have SOAP response which looks like
<soap:Envelope>
<soap:Header>
<AuthorizationToken soap:mustUnderstand="1">
<Token>5c31cca8-8303-4d01-a564-a99569a0963a</Token>
</AuthorizationToken>
</soap:Header>
<soap:Body>
<AuthenticateResponse>
<AuthenticateResult>http://www.avectra.com/OnDemand/2005/</AuthenticateResult>
</AuthenticateResponse>
</soap:Body>
</soap:Envelope>
and no clue how to read data from the header (get a token value). I'm using SoapClient
from PHP5.
回答1:
From http://drupalcode.org/project/netforum.git/blob/refs/heads/master:/xwebSecureOD.class.inc it looks like this should work:
$soapclient->__soapCall($fname, $arguments, null, $this->getAuthHeaders(), $responseHeaders);
$responseHeaders['AuthorizationToken']->Token;
That link has a class that extends PHP's soap object and does some caching and drupal specific things, but you should be able to remove those pieces and be left with a new class that transparently handles the sliding authorization token netFORUM uses.
回答2:
As per the manual:
$soapclient->__soapCall("soapmethod", array(parameters), null, $input_headers, &$output_headers);
$output_headers should then contain the headers from the response message.
回答3:
I got this from JackTheKnife on http://hardforum.com/showthread.php?t=1651481
$result = $service->getLastResponse();
$xmlString = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $result);
$xml = simplexml_load_string($xmlString);
$token = $xml->soapHeader[0]->AuthorizationToken[0]->Token;
来源:https://stackoverflow.com/questions/8124861/how-to-read-data-from-soap-header-in-client-side