繁体   English   中英

php file_get_contents授权标头

[英]php file_get_contents authorization header

任何人都可以解释为什么私有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);
 }

您的代理将回复需要身份验证。 你可能会挠头并想“但我正在提供身份验证!”

问题是'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); 
?> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM