Naf*_*Kay 27 php http basic-authentication
我需要为我正在研究的Flash Player项目构建代理.我只需要使用HTTP-Basic身份验证向另一个URL发出HTTP GET请求,并从PHP提供响应,就像PHP文件是原始源一样.我怎样才能做到这一点?
clo*_*e45 86
Marc B在回答这个问题方面做得很好.我最近采用了他的方法,并希望分享生成的代码.
<?PHP
$username = "some-username";
$password = "some-password";
$remote_url = 'http://www.somedomain.com/path/to/file';
// Create a stream
$opts = array(
'http'=>array(
'method'=>"GET",
'header' => "Authorization: Basic " . base64_encode("$username:$password")
)
);
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$file = file_get_contents($remote_url, false, $context);
print($file);
?>
Run Code Online (Sandbox Code Playgroud)
我希望这对人们有所帮助!
Mar*_*c B 13
使用file_get_contents()
a stream
指定HTTP凭据,或使用curl
和CURLOPT_USERPWD
选项.
归档时间: |
|
查看次数: |
56383 次 |
最近记录: |