我正在开发一个允许用户在 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 在我的服务器上运行得非常好(我已经测试过了)。
有任何想法吗?