stream_context_create授权不起作用

时间:2015-10-02 10:20:48

标签: php xml

如果我使用浏览器登录它可以工作,但是从代码中它会给出授权错误。

 $request='<?xml version="1.0" encoding="UTF-8"?><req:KnownTrackingRequest xmlns:req="http://www.dhl.de"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.dhl.deTrackingRequestKnown.xsd">
<Request>
    <ServiceHeader>
        <MessageTime>2002-06-25T11:28:56-08:00</MessageTime>
        <MessageReference>1234567890123456789012345678</MessageReference>

    </ServiceHeader>
</Request>
<LanguageCode>de</LanguageCode>
<AWBNumber>8564385550</AWBNumber>
<LevelOfDetails>ALL_CHECK_POINTS</LevelOfDetails>
<PiecesEnabled>S</PiecesEnabled></req:KnownTrackingRequest>';

        $context = stream_context_create(
            array(
                'http' => array(
                    'header' => "Authorization: Basic " . base64_encode("a98098880:NEO_dhl83#") . "\r\n" .
                        "Content-type: text/xml \r\n"
                )
            )
        );
      $response = file_get_contents("https://cig.dhl.de/services/sandbox/rest/sendungsverfolgung" . "?xml=" . urlencode($request), false, $context);

如果使用浏览器登录此用户名密码有效但不是这样,不知道我是否犯了一些错误。

0 个答案:

没有答案