Page 1 of 1

fsockopen with http authentication problem

Posted: Wed Feb 08, 2006 11:25 am
by hscbaj
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).

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);
Any ideas with regards to the 404 issue gratefully received.
Thanks
Baj

Posted: Wed Feb 08, 2006 11:32 am
by feyd
tried

Code: Select all

$data = file_get_contents('http://'.$authuser.':'.$authpass.'@'.$host.$url);
:?:

Posted: Wed Feb 08, 2006 11:39 am
by hscbaj
No, but now have... and working.
File this one under "complicating the matter".

Still interested to know why i was getting 404's tho, very odd.