PHP不修改标题信息

时间:2014-12-30 18:37:52

标签: php soap header token

我正在使用soap登录服务器并检索令牌,没问题....

然后我将令牌添加到soap:header。

这就是我正在尝试创造的。

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Header>
    <WSAuthorization xmlns="http://url.com/testing/">
      <Token>string</Token>
    </WSAuthorization>
  </soap12:Header>
  <soap12:Body>
    <ImportDrugTest xmlns="http://url.com/testing/">
      <specimenID>int</specimenID>
      <midasNumber>string</midasNumber>
      <specimenComments>string</specimenComments>
      <nonRXDrugsUsed>string</nonRXDrugsUsed>
      <testCode>string</testCode>
      <testDate>dateTime</testDate>
      <testResult>string</testResult>
      <collectionDate>dateTime</collectionDate>
      <lastName>string</lastName>
      <firstName>string</firstName>
      <middleName>string</middleName>
      <CRUDFlag>string</CRUDFlag>
    </ImportDrugTest>
  </soap12:Body>
</soap12:Envelope>

这就是我得到的

<?xml version="1.0" encoding="UTF-8"?>
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://url.com/testing/">
    <soap-env:header>
        <ns1:wsauthorization />
    </soap-env:header>
    <soap-env:body>
        <ns1:importdrugtest>
            <ns1:specimenid>605431024</ns1:specimenid>
            <ns1:midasnumber>7700MD2005000001.00</ns1:midasnumber>
            <ns1:specimencomments>Miscellaneous</ns1:specimencomments>
            <ns1:nonrxdrugsused>N/A</ns1:nonrxdrugsused>
            <ns1:testcode>025000</ns1:testcode>
            <ns1:testdate>2012-09-24</ns1:testdate>
            <ns1:testresult>Negative</ns1:testresult>
            <ns1:collectiondate>2012-09-25</ns1:collectiondate>
            <ns1:lastname>Last</ns1:lastname>
            <ns1:firstname>First</ns1:firstname>
            <ns1:middlename>Middle</ns1:middlename>
            <ns1:crudflag>C</ns1:crudflag>
        </ns1:importdrugtest>
    </soap-env:body>
</soap-env:envelope>

这是我的代码。 注意:我已经注意到了一个新的SoapClient()并重新获得了令牌。

$ns = 'http://url.com/testing/';
// $headerParams = array('WSAuthorization'=>array('token'=>$token)); tried this also
$headerParams = array('token'=>$token); 
$header = new SoapHeader($ns, 'WSAuthorization', $headerParams);       

$client->__setSoapHeaders($header);

$param = array('ImportTest' => array( 
                'specimenID'  => '0605431024',
                'midasNumber' => '7700MD2005000001.00',
                'county' => '03',
                'site' => '00',
                'specimenComments' => 'Miscellaneous',
                'nonRXDrugsUsed' => 'N/A',
                'testCode'  => '025000',
                'testDate' => '2012-09-24',
                'testResult' => 'Negative',
                'collectionDate' => '2012-09-25',
                'lastName' => 'Last',
                'firstName' => 'First',
                'middleName'  => 'Middle',
                'CRUDFlag'  => 'C'
            ));

$result = $client->__soapCall('ImportDrugTest', $param);

2014年12月31日更新

我修改了代码并添加了print_r($ header):

$ns = "http://url.com/testing/";
$headerParams = array('token'=>$token); 
$header = new SoapHeader($ns, 'WSAuthorization', $headerParams);       
print_r($header);
$client->__setSoapHeaders(array($header)); // even tried $client->__setSoapHeaders($header);

我明白了:

SoapHeader Object
(
    [namespace] => http://url.com/testing/
    [name] => WSAuthorization
    [data] => Array
        (
            [token] => UDjVSzGt9J4fKuRuoFHau3gy4CoLo//VlnuZv5oy5tjKPffIeSc+dx7EEDIfosVkVHDD0G/ZBANnCzPmRBo6CIusRL5rak5QdYI9jD7209c=
        )

    [mustUnderstand] => 
)

但是__getLastRequest()给了我这个:

<soap-env:header>
    <ns1:wsauthorization />
</soap-env:header>

我错过了什么?

1 个答案:

答案 0 :(得分:0)

这有效:

$headerParams = array('Token'  => $token);
$header     = new SoapHeader($NameSpace, 'WSAuthorization', $headerParams, false);

我遇到的问题是由于没有从响应中解析出令牌而引起的。