Reputation: 4542
Note Issue appear in Azure Server.It wont allow get details to CURL.
I have an issue with a display post in footer.When I try to get it via file_get_content
as well as used a CURL
but still have issue.
$url="https://medium.com/@username/latest?format=json";
$homepage = file_get_contents($url);
echo "<pre>";
print_r($homepage);
echo "</pre>";
Its work in a Linux but when I move to windows Azure after this it will give following error.
Warning: file_get_contents(https://medium.com/@username/latest?format=json) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden
Upvotes: 0
Views: 325
Reputation: 2654
I think your problem is missing User-agent in your request. Better use cURL with User-agent option:
function curl_get_contents($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
Now you can get content of endpoint like this:
$url="https://medium.com/@hackernoon/latest?format=json";
$homepage = curl_get_contents($url);
echo "<pre>";
print_r($homepage);
echo "</pre>";
Upvotes: 1