GuessIt - Web API PHP 中的卷曲请求
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>
这是一些信息 about the 502 error。
我正在尝试使以下 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>
这是一些信息 about the 502 error。