首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Rapidgator API直接下载链接错误

Rapidgator API直接下载链接错误
EN

Stack Overflow用户
提问于 2018-10-16 16:07:52
回答 1查看 1.5K关注 0票数 0

伙计们,我目前正在研究文件托管高级链接生成器,基本上这将是一个网站,你可以从那里获得一个高级链接uptobox,rapidgator,uploaded.net和其他文件主机网站,而无需购买高级帐户。基本上,我们是代表用户购买这个网站的帐户,并以低价格提供这项服务。所以当我设置rapidgator的直接下载链接的API时,我能够获得该链接,但我得到的会话结束了。我试图通过软件来实现API,而不是通过手动编码,而我正面临着这个问题

所以我一直在从Tihs站点获取Rapidgator API参考:- https://gist.github.com/Chak10/f097b77c32a9ce83d05ef3574a30367d

所以我正在用我的调试软件做以下事情,我得到了成功的响应,但当我在浏览器中打开该URL时,它显示会话Id失败。

下面是我在https://rapidgator.net/api/user/login上发送一个包含用户名和数据的post请求的步骤,并得到以下输出

代码语言:javascript
运行
复制
{"response":{"session_id":"g8a13f32hr4cbbbo54qdigrcb3","expire_date":1542688501,"traffic_left":"13178268723435"},"response_status":200,"response_details":null}

现在,我在这个url上发送get请求(我也尝试了Post请求,但也发生了同样的事情),URL中嵌入了会话id和URL https://rapidgator.net/api/file/download?sid=&url=,我得到了以下输出

代码语言:javascript
运行
复制
{"response":{"url":"http:\/\/pr56.rapidgator.net\/\/?r=download\/index&session_id=uB9st0rVfhX2bNgPrFUri01a9i5xmxan"},"response_status":200,"response_details":null}

当我尝试通过浏览器从Url下载文件时,它显示无效的会话,有时还会显示打开的连接太多错误

错误链接:- https://i.imgur.com/wcZ2Rh7.png成功响应:- https://i.imgur.com/MqTsB8Q.png

EN

回答 1

Stack Overflow用户

发布于 2018-11-30 22:13:45

Rapidgator需要它的api被不同的URL点击三次。

代码语言:javascript
运行
复制
 $cookie = $working_dir.rand();
 $headers = array("header"=>"Referer: https://rapidgator.net");

     $ch = curl_init();
           curl_setopt($ch, CURLOPT_URL, "http://rapidgator.net/api/user/login");
           curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
           curl_setopt($ch, CURLOPT_POSTFIELDS, "username=email@domain.ext&password=myplaintextpassword");
           curl_setopt($ch, CURLOPT_POST, 1);
           curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
           curl_setopt($ch, CURLOPT_HEADER, 0);
           curl_setopt($ch, CURLOPT_VERBOSE, 0);
           curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
           curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
           curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
           curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
           curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
           curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 $result = curl_exec($ch);
           curl_close ($ch);

 $rapidgator_json = json_decode($result,true);
 return array($rapidgator_json['response']['session_id'],$cookie);

以上链接中的http://rapidgator.net/api/user/login (这是初始登录)为您提供了所需的会话id。响应采用JSON格式

现在我们需要请求一个下载链接,它允许我们在不登录到人工输入表单的情况下进行下载。因此,我们将使用它的api来请求一个下载链接,该链接使用我们从第一个url获得的初始会话id。

代码语言:javascript
运行
复制
 $headers = array("header"=>"Referer: http://rapidgator.net/api/user/login");

     $ch = curl_init();
           curl_setopt($ch, CURLOPT_URL, "http://rapidgator.net/api/file/download?sid=$rapidgator_session&url=$rapidgator_file");
           curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
           curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
           curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
           curl_setopt($ch, CURLOPT_HEADER, 0);
           curl_setopt($ch, CURLOPT_VERBOSE, 0);
           curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
           curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
           curl_setopt($ch, CURLOPT_COOKIEJAR, $working_dir.$rapidgator_cookie);
           curl_setopt($ch, CURLOPT_COOKIEFILE, $working_dir.$rapidgator_cookie);
           curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
           curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 $result = curl_exec($ch);
           curl_close ($ch);

 $rapidgator_json = json_decode($result,true);
 return array($rapidgator_json['response']['url']);

基本上,我们传递Rapidgator给我们的会话id,假设你已经正确传递了一个有效的帐户。然后,我们将包含您获得的源url (链接到文件) http://rapidgator.net/api/file/download?sid=$rapidgator_session&url=$rapidgator_file

在那之后。Rapidgator将返回一个带有url的JSON响应,您可以使用该url获取有问题的文件。这允许您使用任何您想要的下载方法,因为该链接是一个会话,url在短时间内有效。

代码语言:javascript
运行
复制
$rapidgator_json['response']['url']

上面的所有代码都有些不完整。建议对json响应进行一些额外的检查,以确定可能的错误/限制。我在我的一端使用了函数,但这足以让您看到您应该做什么。Rapidshare API还有其他数据,可以用来确定你是否已经超过了每天的配额。会话url将持续多长时间等等。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52830731

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档