簡體   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