【问题标题】:Indy TIdHTTPResponseInfo.ContentType not being setIndy TIdHTTPResponseInfo.ContentType 未设置
【发布时间】:2013-05-29 14:04:41
【问题描述】:

我写了一个 TIdHTTPServer 网络服务器。 Indy 版本是 10,Delphi 是 2007。

我使用以下代码发回 jpeg、gif、png 等文件:

      AResponseInfo.ServeFile(AContext,rootpath+ARequestInfo.document);
      AResponseInfo.ContentType := 'image/jpeg';
      AResponseInfo.ContentType := GetMimeTypeFromFile('.'+ExtractFileDir(rootpath+ARequestInfo.document));

图像在所有浏览器中都能正常显示。但我看到(通过 Chrome 中的控制台)它们被返回为 MIME 类型:text/html。 我已经尝试了 image/jpegGetMIMTypeFromFile 方法,并且都产生了 text/html。

我还需要打另一个电话吗?我在其他线程中看到了对 AResponseInfo.WriteHeader 函数的调用。但添加后会引发异常,标头被写入两次。

【问题讨论】:

    标签: delphi indy indy10


    【解决方案1】:

    其实发现问题了。需要在 ServeFile 调用之前指定内容类型。

      AResponseInfo.ContentType := 'image/jpeg';
      AResponseInfo.ServeFile(AContext,rootpath+ARequestInfo.document);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-13
      • 2021-04-04
      • 2013-01-07
      相关资源
      最近更新 更多