相关疑难解决方法(0)

使用PHP中的摘要身份验证卷曲请求下载Bitbucket私有存储库

我试着在php上做这个请求,从我的Bitbucket私有存储库下载最后一个源:

curl --digest --user user:pass https://bitbucket.org/user/repo/get/tip.zip -o test.zip
Run Code Online (Sandbox Code Playgroud)

在命令行它确定,文件下载完美,但在PHP不工作,这我的PHP代码:

$out = fopen('test.zip', 'w+');
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERPWD, 'user:pass');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FILE, $out);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, 'https://bitbucket.org/user/repo/get/tip.zip');
curl_exec($ch);
Run Code Online (Sandbox Code Playgroud)

这是响应,登录无效,服务器重定向到登录页面:

Error CURL: '' 
Error number: 0
Array
(
    [url] => https://bitbucket.org/account/signin/?next=/user/repo/get/tip.tar.gz
    [content_type] => text/html; charset=utf-8
    [http_code] => 200
    [header_size] => 1099
    [request_size] => 194
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => …
Run Code Online (Sandbox Code Playgroud)

php command-line curl bitbucket digest-authentication

12
推荐指数
1
解决办法
1万
查看次数