duanchi19820419 2013-07-31 12:05
浏览 46
已采纳

Reddit API和cURL创建帐户的问题

I'm working on an app that allows users to create an account on reddit (and more). I use cURL and PHP to interface with the Reddit API, this is my code:

    function create_account($username, $password, $captcha_iden, $captcha_answer){

    $url = "http://reddit.com/api/register";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_POST, true);

    $data = "user=$username&passwd=$password&passwd2=$password&rem=false&reason=redirect&api_type=json&iden=$captcha_iden&captcha=$captcha_answer";

    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

    $curl_scraped_page = curl_exec($ch);

    die($curl_scraped_page);
    curl_close($ch);


}

However, all I receive from the Reddit servers is this:

HTTP/1.1 302 Moved Temporarily 
Server: AkamaiGHost 
Content-Length: 0 
Location: http://www.reddit.com/api/register 
Date: Wed, 31 Jul 2013 20:02:03 GMT 
Connection: keep-alive 

HTTP/1.1 404 Not Found 
Content-Length: 0 
Content-Type: text/html; charset=UTF-8   
Server: '; DROP TABLE servertypes; -- 
Vary: Accept-Encoding 
Date: Wed, 31 Jul 2013 20:02:04 GMT 
Connection: keep-alive

I'm not entirely sure what that HTTP response means and I'm really confused on how to fix this. cURL runs perfectly fine on my server (I have tested it).

Any ideas?

展开全部

  • 写回答

1条回答 默认 最新

  • douyan6958 2013-07-31 12:23
    关注

    The first part of the response is switching you over from reddit.com to www.reddit.com. I'm assuming the second request is making a GET, which is not accepted for that endpoint (only POST according to the docs) and so it returns the 404. Try updating the original URL to include the www. and see if that works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 vscode开发micropython,import模块出现异常
  • ¥20 Excel数据自动录入表单并提交
  • ¥30 silcavo仿真,30分钟,只需要代码
  • ¥15 FastReport 怎么实现打印后马上关闭打印预览窗口
  • ¥15 利用3支股票数据估计其均值和方差的95%置信区间。
  • ¥15 微信小程序运行一项功能时,弹出未知错误弹框,检查代码没有问题
  • ¥15 ATAC测序生成self-pseudo replicates之前是否要进行去线粒体reads
  • ¥15 python模糊字匹配函数问题
  • ¥20 谁刷目标页面的uv记录器上数据,数据只记录跳转的数值
  • ¥30 数据库软件的安装方法
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部