fsockopen with http authentication problem
Posted: Wed Feb 08, 2006 11:25 am
Im trying to retrieve an xml feed behind http authentication.
Using the following code, im finding that no matter what URL i specify, whether i use authentication or not, im getting a 404 every time, even when the url's exist (ive tried 3 entirely different domains).
Any ideas with regards to the 404 issue gratefully received.
Thanks
Baj
Using the following code, im finding that no matter what URL i specify, whether i use authentication or not, im getting a 404 every time, even when the url's exist (ive tried 3 entirely different domains).
Code: Select all
$host='www.beenhamband.org.uk';
$url='/contact.php';
$authuser='foo'; // blah ?
$authpass='bar'; // blah ?.
$authenc=base64_encode("$authuser:$authpass");
$hdr =sprintf("GET %s HTTP/1.0\r\n", $url);
$hdr .="Accept: text/html\r\nAccept: text/plain\r\n";
$hdr .="User-Agent: Mozilla/1.0 ()\r\n";
$hdr .="Authorization: Basic $authenc\r\n\r\n";
$fp = fsockopen($host , 80, &$errno, &$errstr, 30);
if (!$fp) {
//die "$host open error: $errstr $errno .\n";
}
fputs($fp,$hdr);
while(!feof($fp)) {
$buff=fgets($fp,2048);
echo $buff;
}
fclose($fp);Thanks
Baj