Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using fsockopen to retrive compressed HTML page

Status
Not open for further replies.

philclare

Programmer
Jul 31, 2003
34
GB
Hi,

I am using fsockopen to retrieve an HTML page that has been compressed, but when I try and decompress the string I get the following error :

Warning: gzuncompress() [function.gzuncompress]: data error

I found a bug report on the PHP pages at sourceforge that said it was something to do with the gzip header and the workaround was to write the string to a temp file then read it in using the gzip file routines. I don't want to do this because there will be a lot of requests, anybody got any ideas?

I have attached the code here but it won't work on your systems because of the url.

$request.="POST ".$HBD['urlinfo']['path']." HTTP/1.1\n";
$request.="Host: ".$HBD['urlinfo']['host']."\n";
$request.="Referer: ".$HBD['referer']."\n";
$request.="Content-type: application/x- $request.="Content-length: ".strlen($HBD['RQ'])."\n";
if($HBD['decompress']){
$request.="Accept-Encoding: gzip, deflate\n";
}
$request.="Connection: close\n";
$request.="\n";
$request.=$HBD['RQ']."\n";

$fp = fsockopen($HBD['urlinfo']['host'],80);
fputs($fp, $request);
$HBDResult='';
while(!feof($fp)) {
$HBDResult .= fgets($fp, 128);
}
fclose($fp);

$HBDResult = substr($HBDResult,strpos($HBDResult,"\r\n\r\n"));

if($HBD['decompress']){
$HBDResult = gzuncompress($HBDResult);
}

Thanks

Hope this helps,

Phil Clare
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top