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 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法