繁体   English   中英

cURL 不跟随位置:header

[英]cURL not following the Location: header

我正在尝试使用 Rapidshare 的 API 下载文件。 为此,我需要两次请求他们的download子程序。 一次是要使用适当的下载服务器,其次是在第一个请求给我的服务器上再次请求下载。 第二个调用是发送文件的内容。

在第一次调用时,它返回一个带有Location: blah字段的 header,我需要遵循这个位置。 所以我这样做了:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=download&fileid=$file_id&filename=$file_name&try=1&login={$account['username']}&password={$account['password']}");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$resp = curl_exec($ch);
curl_close($ch);

不幸的是,它似乎没有跟随位置 header,因为$resp没有返回任何内容。 If I put the URL in my browser, it successfully follows the location header and gives me the output of the API call, so it must be something wrong with PHP or cURL.

任何人都可以冒险猜测它可能是什么吗? 我现在已经摆弄了 30 分钟,也不知道。

谢谢你的帮助!

将 CURLOPT_HEADER 更改为 true。

curl_setopt($ch, CURLOPT_HEADER, 1);

如果我正确阅读了文档,它将返回请求页面的标题,其中包含“Location”指令,并且通过将 CURLOPT_FOLLOWLOCATION 设置为 true,它应该遵循该重定向,并且通过 Location 指令进行任何其他操作。

暂无
暂无

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

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