duanchi19820419 2013-07-31 20: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 20: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 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启