You are here: Re: fsockopen error need some help thanks « PHP Programming Language « IT news, forums, messages
Re: fsockopen error need some help thanks

Posted by The GOsh! :D on 11/25/06 14:28

This is another Solution is this, but think that you'll need to analize
the headers for decompress is the content is compressed or am I wrong?:

<?php
$host = "www.example.com";
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Accept-Language: en-us, en;q=0.50\r\n";
$out .= "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n";
$out .= "Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66\r\n";
$out .= "Connection: Close\r\n\r\n";

fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}

?>


On Nov 25, 10:15 am, Andy Hassall <a...@andyh.co.uk> wrote:
> On 25 Nov 2006 05:53:54 -0800, sad...@gmail.com wrote:
>
>
>
> >Solution One
> ><?php
> >$host = "www.example.com";
> >$fp = fsockopen($host, 80, $errno, $errstr, 30);
> >if (!$fp) {
> > echo "$errstr ($errno)<br />\n";
> >} else {
> > $out = "GET / HTTP/1.1\r\n";
> > $out .= "Host: $host\r\n";
> > $out .= "Connection: Close\r\n\r\n";
>
> > fwrite($fp, $out);
> > while (!feof($fp)) {
> > echo fgets($fp, 128);
> > }
> > fclose($fp);
> >}
> >?> This has a common but serious mistake - you're claiming to be an HTTP/1.1
> client, but you haven't implemented Chunked transfer encoding. This is a
> mandatory requirement for HTTP/1.1 clients, and it's quite common that servers
> use it. If you don't handle it, the data will appear to be "corrupted".
>
> The other solutions you posted use PHP's built-in HTTP user agent code, which
> does handle this encoding correctly. Alternatively the code above could be
> changed to use HTTP/1.0.
>
> --
> Andy Hassall :: a...@andyh.co.uk ::http://www.andyh.co.ukhttp://www.andyhsoftware.co.uk/space:: disk and FTP usage analysis tool

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация