GuessIt-PHP中的Web API Curl请求


GuessIt - Web API Curl Request in PHP

我正在尝试让以下cURL请求正常工作。API页面上显示的命令行cURL GET请求是:

curl "http://guessit.io/guess?filename=House.of.Cards.2013.S02E03.1080p.NF.WEBRip.DD5.1.x264-NTb.mkv"

网页API为:http://api.guessit.io/

到目前为止,我的代码是:

<?php
$url = "http://guessit.io/guess?filename=";
//This adds a filename to the URL 
$theurl = $url . $current->name;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$theurl);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, true); 
// Send the request & save response to $resp
$resp = curl_exec($ch);
$result = file_get_contents($theurl);
// Will dump a beauty json :3
var_dump(json_decode($result, true));
echo $resp;
// Close request to clear up some resources
curl_close($ch);
?>

我会得到什么样的回应?它是JSON吗?

我有一个更重要的问题:用PHP中的这个API获得响应的正确代码是什么?

如果有任何帮助,我将不胜感激。

谢谢。


更新:答案是正确的,但网关响应错误是因为web服务API当时不工作。

您将得到一个502 Bad Gateway错误的HTML响应。前往"http://guessit.io"还显示502.

以下是在终端中执行的相同curl请求:

$ curl "http://guessit.io/guess?filename=House.of.Cards.2013.S02E03.1080p.NF.WEBRip.DD5.1.x264-NTb.mkv"
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.6.2</center>
</body>
</html>

以下是有关502错误的一些信息。