|
I'm having trouble understanding why fsockopen() returns null yet the
errstring/errno value yields:
"The operation completed successfully. (0)"
Here's the code (modified from an example found on many websites - google
"fsockopen php example")
<?php
$url =
'http://waterdata.usgs.gov/wa/nwis/uv?dd_cd=01&dd_cd=02&format=rdb&period=1&
site_no=12149000';
// $url = 'www.php.net';
$fp = fsockopen ($url, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET / HTTP/1.1\r\nHost: ".$url."\r\n\r\n");
while (!feof($fp)) {
echo fgets ($fp,128);
}
fclose ($fp);
}
?>
Some further info: When $url = 'www.php.net', the requested page is
correctly returned. However, when I try to get the USGS page, $fp is 0 and
$errstr/$errno indicates everything is kosher.
What have I missed? How must I structure the url and/or fputs arguments to
correctly obtain this page?
Thanks, in advance,
Cheers
Michael |