0

After poking at this for an hour, I'm stuck. All the commented out urls work just fine. The gov data one fails though. Any thoughts?

//  $url = 'http://en.wiktionary.org/w/api.php?format=json&action=query&titles=work&rvprop=content&prop=revisions&redirects=1';
$url = "http://forecast.weather.gov/MapClick.php?lat=39.1666&lon=-86.5215&unit=0&lg=english&FcstType=dwml";
//$url = 'http://www.reddit.com/r/bloomington/.rss';
//$url = "http://forecast.weather.gov/MapClick.php?lat=34.12699&lon=-118.27381&unit=0&lg=english&FcstType=dwml";

$myReadAccess=new ReadFile($url);

if(!$data=$myReadAccess->getFileContents()){
    //ERROR, DISPLAY ERROR MESSAGE
    echo "Error: " . $myReadAccess->getError();
}
else{
    //SUCCESS, DISPLAY FILE CONTENTS
    echo $data;
}

Read File Class http://pastebin.com/8pQxfsz7

1 Answer 1

1

Try to use cURL

I've tried your code and it produces this error.

file_get_contents(http://forecast.weather.gov/MapClick.php?lat=39.1666&lon=-86.5215&unit=0&lg=english&FcstType=dwml): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden

Then I came across this link and everything works just fine.

Hope it helps..

1
  • thanks, would love a non cURL way, but if it has to be that, it gets the job done
    – Serhiy
    Jun 9, 2015 at 3:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.