Gov Weather XML data feed failing on me

510 views Asked by At

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

There are 1 answers

1
choz On BEST ANSWER

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