Garbage in download result (Indy, Delphi 2009)

256 views Asked by At

I'm using Indy (Delphi 2009) to query .php file on my free hosting site. That .php reads parameters provided with URL, downloads certain page from 3rd party site and echoes back the source. Everything works OK, but some garbage always precedes the useful information that I download. In Firefox I don't see any of it.

Delphi part:

    MSource.Lines.Text := IdHTTP1.Get('http://*****.comuv.com/somefile.php?type=upl&id=' + MUsers.Lines.Strings[i]);

.PHP part:

    header('Content-type: text/plain');
    ...
   else if ($_GET['type'] == 'upl')
{
    $NextChunkURL = 'http://gdata.youtube.com/feeds/api/users/%UserName%/uploads?start-index=1&max-results=25';
    $NextChunkURL = str_replace('%UserName%', $_GET['id'], $NextChunkURL);

    $CurChunk = file_get_contents($NextChunkURL);

    if ($CurChunk == FALSE)
        $CurChunk = 'error downloading [' . $NextChunkURL . ']';

    echo $CurChunk;
}

Output example:

    User account closed //GARBAGE IS HERE !!! (always present and looks the same to me)
    <!-- Hosting24 Analytics Code -->
    <script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
    <!-- End Of Analytics Code -->

Firefox developer kit code:

    <html><head><link rel="alternate stylesheet" type="text/css" href="resource://gre-resources/plaintext.css" title="Переносить длинные строки"></head>
    <body><pre>User account closed
    &lt;!-- Hosting24 Analytics Code --&gt;&lt;script type="text/javascript"
    src="http://stats.hosting24.com/count.php"&gt;&lt;/script&gt;
    &lt;!-- End Of Analytics Code --&gt;
    </pre></body></html>
1

There are 1 answers

0
AmigoJack On

 is #$EF#$BB#$BF and is the UTF-8 BOM, so it's a server problem, not a client one. Only one BOM or none is expected, but your server is sending 4 of them. Viewing that site in "Firefox developer kit" is already an interpretation, and opening that file in a text editor probably "works" aswell, since most of them interprete it. As a counter evidence save your site in Firefox as HTML and open it in a hex editor and you'll see the BOMs just like in your program.