php file_get_contents授权标头

Jef*_*eff 8 php file-get-contents

任何人都可以解释为什么私有bitbucket存储库的授权功能在我的本地机器上运行(运行PHP版本5.3.17),但未在我的远程服务器上授权(运行PHP版本5.3.20)

我本身并没有得到错误 - 我只是从bitbucket得到了一个"禁止"的回应.但是从我的本地服务器运行一切都很好.

function bitBucketConnect($url){
    global $bitPassword;
    global $bitUsername;
    $context = stream_context_create(array(
     'http' => array(
       'header' => "Authorization: Basic " . base64_encode("$bitUsername:$bitPassword")
       )
    ));

 // Make the request
 return file_get_contents($url, false, $context);
 }
Run Code Online (Sandbox Code Playgroud)

小智 9

您的代理将回复需要身份验证.你可能会低头思考"但我正在提供身份验证!"

问题是'header'值仅适用于http连接.因此,要在代理上进行身份验证,首先必须从HTTP中提取文件,然后才能在FTP上使用上下文.

<?php 
$opts = array('ftp' => array( 
    'proxy' => 'tcp://vbinprst10:8080', 
    'request_fulluri'=>true, 
    'header' => array( 
        "Proxy-Authorization: Basic $auth" 
        ) 
    ), 
    'http' => array( 
    'proxy' => 'tcp://vbinprst10:8080', 
    'request_fulluri'=>true, 
    'header' => array( 
        "Proxy-Authorization: Basic $auth" 
        ) 
    ) 
); 
$context = stream_context_create($opts); 
$s = file_get_contents("http://www.example.com",false,$context); 
$s = file_get_contents("ftp://anonymous:anonymous@ftp.example.org",false,$context); 
?> 
Run Code Online (Sandbox Code Playgroud)