【问题标题】:having an html file downloaded instead of displayed下载而不是显示 html 文件
【发布时间】:2023-03-25 00:15:01
【问题描述】:

我正在编写一个基于 Web 的文件管理员。单击而不是显示链接时如何下载 html 文件。

【问题讨论】:

    标签: html http web-applications


    【解决方案1】:

    在服务器端,在提供文件时,添加此标头:

    Content-Disposition: attachment; filename="document.html"
    

    例如在 PHP 中你会这样做:

    header('Content-Disposition: attachment; filename="document.html"');
    

    【讨论】:

      【解决方案2】:

      在响应标头中,将 Content-Disposition 设置为 "attachment; filename=something.html"

      【讨论】:

        【解决方案3】:

        将 HTTP 响应的 Content-Type 标头设置为“application/octet-stream”。

        在 ASP.net/C# 中

        Response.ContentType = "application/octet-stream";
        

        【讨论】:

          【解决方案4】:

          当请求该文件时,服务器需要返回不同的 MIME 类型,例如 application/octet-stream。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2013-12-02
            • 2013-12-26
            • 1970-01-01
            • 2018-11-10
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多