我正在尝试在 php 上执行此请求,以从我的 Bitbucket 私有存储库下载最后一个源:
curl --digest --user user:pass https://bitbucket.org/user/repo/get/tip.zip -o test.zip
在命令行中没问题,文件下载完美,但在 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);
这是响应,登录无效,服务器重定向到登录页面:
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] => 1
[total_time] => 1.055465
[namelookup_time] => 1.5E-5
[connect_time] => 0.102969
[pretransfer_time] => 0.216164
[size_upload] => 0
[size_download] => 10049
[speed_download] => 9520
[speed_upload] => 0
[download_content_length] => 10049
[upload_content_length] => 0
[starttransfer_time] => 0.527512
[redirect_time] => 0.527519
[redirect_url] =>
)
任何人都知道我可以如何解决我的问题?非常感谢!!!