袅袅不继地点:包头 [英] cURL not following the Location: header

查看:153
本文介绍了袅袅不继地点:包头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用免费电子的API来下载文件。要做到这一点,我需要请求其下载子程序的两倍。一旦获得合适的下载服务器使用,二来是第一个请求给我的服务器上再次请求下载。第二个电话是发送文件。

I'm trying to use Rapidshare's API to download a file. To do so, I need to request their download subroutine twice. Once to get the appropriate download server to use, and secondly to request the download again on the server that the first request gave me. The second call is what sends the file.

在第一次调用,它返回一个位置的标题:等等字段,我需要遵循这一位置。所以,我没有这样的:

On the first call, it returns a header with a Location: blah field, and I need to follow this location. So I did this:

$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);

不幸的是,它似乎并没有成为继位置标头,因为没有在 $ RESP 返回。如果我把网址在浏览器中,它成功地沿用了位置标头,并给我的API调用的输出,因此它必须是什么毛病PHP或卷曲。

Unfortunately, it doesn't seem to be following the location header, because nothing is being returned in $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分钟分钟现在不知道。

Can anyone hazard a guess on what it might be? I've been fiddling for 30 minutes minutes now and have no idea.

感谢您的帮助!

推荐答案

改变CURLOPT_HEADER为true。

change the CURLOPT_HEADER to true.

curl_setopt($ch, CURLOPT_HEADER, 1);

如果我读过的文档的权利,这将返回所请求的页面的heaader,以包含位置指令,并且由有CURLOPT_FOLLOWLOCATION设置为true,它应该遵循重定向,并通过Location指示任何人。

If I've read the documentation right, that will return the requested page's heaader, with contains the "Location" Directive, and by having CURLOPT_FOLLOWLOCATION set to true it should follow that redirect, and any others via the Location directive.

这篇关于袅袅不继地点:包头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆