我得到了以下错误:
警告:file_get_contents(https://www.readability.com/api/content/v1/parser?url=http://www.redmondpie.com/ps1-and-ps2-games-will-be-playable-on-playstation-4-very-soon/?utm_source=dlvr.it&utm_medium=twitter&token=MYAPIKEY) [function.file-get-contents]:打开流失败!HTTP/1.1 404 NOT FOUND in /home/DIR/htdocs/readability.php on line 23
通过一些回显,我得到了函数解析的URL,并且它是正确和有效的,我从浏览器中进行请求也是可以的。
问题是我使用file_get_contents时得到了上述错误,我真的不明白为什么。
URL是有效的,函数没有被免费托管服务阻止(所以我不需要Curl)。
如果有人能发现我的代码中的错误,我将不胜感激!谢谢...
这是我的代码:
警告:file_get_contents(https://www.readability.com/api/content/v1/parser?url=http://www.redmondpie.com/ps1-and-ps2-games-will-be-playable-on-playstation-4-very-soon/?utm_source=dlvr.it&utm_medium=twitter&token=MYAPIKEY) [function.file-get-contents]:打开流失败!HTTP/1.1 404 NOT FOUND in /home/DIR/htdocs/readability.php on line 23
通过一些回显,我得到了函数解析的URL,并且它是正确和有效的,我从浏览器中进行请求也是可以的。
问题是我使用file_get_contents时得到了上述错误,我真的不明白为什么。
URL是有效的,函数没有被免费托管服务阻止(所以我不需要Curl)。
如果有人能发现我的代码中的错误,我将不胜感激!谢谢...
这是我的代码:
<?php
class jsonRes{
public $url;
public $author;
public $url;
public $image;
public $excerpt;
}
function getReadable($url){
$api_key='MYAPIKEY';
if(isset($url) && !empty($url)){
// I tried changing to http, no 'www' etc... -THE URL IS VALID/The browser opens it normally-
$requesturl='https://www.readability.com/api/content/v1/parser?url=' . urlencode($url) . '&token=' . $api_key;
$response = file_get_contents($requesturl); // * here the code FAILS! *
$g = json_decode($response);
$article_link=$g->url;
$article_author='';
if($g->author != null){
$article_author=$g->author;
}
$article_url=$g->url;
$article_image='';
if($g->lead_image_url != null){
$article_image=$g->lead_image_url;
}
$article_excerpt=$g->excerpt;
$toJSON=new jsonRes();
$toJSON->url=$article_link;
$toJSON->author=$article_author;
$toJSON->url=$article_url;
$toJSON->image=$article_image;
$toJSON->excerpt->$article_excerpt;
$retJSONf=json_encode($toJSON);
return $retJSONf;
}
}
?>
file_get_contents()
对于远程URL来说是一个非常笨重的工具。 - user557846