【问题标题】:GuessIt - Web API Curl Request in PHPGuessIt - PHP 中的 Web API 卷曲请求
【发布时间】: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 不工作。

【问题讨论】:

    标签: php api curl get


    【解决方案1】:

    您将收到针对 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

    【讨论】:

    • 谢谢,我如何在 PHP 中获取正确的代码以获得正确的响应?
    • 我不确定您所说的正确响应是什么意思。无论您使用何种方式执行请求,响应都将是 502 错误。 guessit 服务似乎无法正常工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-23
    • 2014-08-21
    • 2018-04-08
    • 2011-09-16
    • 2014-11-11
    • 2018-09-20
    • 2019-01-27
    相关资源
    最近更新 更多