【发布时间】:2015-03-26 21:17:45
【问题描述】:
我正在尝试使以下 cURL 请求正常工作。 API页面显示的命令行cURL GET请求为:
curl "http://guessit.io/guess?filename=House.of.Cards.2013.S02E03.1080p.NF.WEBRip.DD5.1.x264-NTb.mkv"
Web 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 不工作。
【问题讨论】: