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 Andy Hassall on 11/25/06 14:15

On 25 Nov 2006 05:53:54 -0800, saddor@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 :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://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

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