【问题标题】:Issue with Reddit API and cURL creating an accountReddit API 和 cURL 创建帐户的问题
【发布时间】:2013-08-01 12:57:42
【问题描述】:

我正在开发一个允许用户在 reddit(以及更多)上创建帐户的应用程序。我使用 cURL 和 PHP 与 Reddit API 交互,这是我的代码:

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


}

但是,我从 Reddit 服务器收到的只是以下内容:

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

我不完全确定 HTTP 响应是什么意思,我真的很困惑如何解决这个问题。 cURL 在我的服务器上运行得非常好(我已经测试过了)。

有什么想法吗?

【问题讨论】:

    标签: php api http curl reddit


    【解决方案1】:

    响应的第一部分是将您从reddit.com 切换到www.reddit.com。我假设第二个请求正在发出 GET,该端点不接受该请求(根据文档仅 POST),因此它返回 404。尝试更新原始 URL 以包含 www. 并查看是否有效.

    【讨论】:

    • 无耻插件:您还可以使用 Runscope 解决此类问题并全面了解请求/响应。
    • 谢谢!这就是问题所在。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-11
    • 2016-03-02
    • 1970-01-01
    • 2017-07-17
    • 1970-01-01
    • 2020-04-30
    • 1970-01-01
    相关资源
    最近更新 更多