【问题标题】:Garbage in download result (Indy, Delphi 2009)下载结果中的垃圾(Indy,Delphi 2009)
【发布时间】:2014-11-11 12:21:59
【问题描述】:

我正在使用 Indy (Delphi 2009) 在我的免费托管网站上查询 .php 文件。该 .php 读取 URL 提供的参数,从 3rd 方站点下载特定页面并回显源。一切正常,但一些垃圾总是在我下载的有用信息之前。在 Firefox 中,我看不到任何内容。

德尔福部分:

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

.PHP部分:

    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;
}

输出示例:

    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 开发者工具包代码:

    <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>

【问题讨论】:

    标签: php delphi download indy byte-order-mark


    【解决方案1】:

    #$EF#$BB#$BF 并且是 UTF-8 BOM,所以这是服务器问题,而不是客户端问题。预计只有一个 BOM 或没有,但您的服务器正在发送其中的 4 个。在“Firefox 开发者工具包”中查看该站点已经是一种解释,并且在文本编辑器中打开该文件也可能“有效”,因为他们中的大多数人都会解释它。作为反证,在 Firefox 中将您的网站保存为 HTML 并在十六进制编辑器中打开它,您将看到 BOM 就像在您的程序中一样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-13
      • 1970-01-01
      • 1970-01-01
      • 2021-11-23
      • 2012-07-15
      • 1970-01-01
      • 2013-07-23
      • 2010-10-07
      相关资源
      最近更新 更多