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

Serhiy
  • 2,505
  • 3
  • 33
  • 49

1 Answers1

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..

Community
  • 1
  • 1
choz
  • 17,242
  • 4
  • 53
  • 73