【发布时间】:2023-03-25 00:15:01
【问题描述】:
我正在编写一个基于 Web 的文件管理员。单击而不是显示链接时如何下载 html 文件。
【问题讨论】:
标签: html http web-applications
我正在编写一个基于 Web 的文件管理员。单击而不是显示链接时如何下载 html 文件。
【问题讨论】:
标签: html http web-applications
在服务器端,在提供文件时,添加此标头:
Content-Disposition: attachment; filename="document.html"
例如在 PHP 中你会这样做:
header('Content-Disposition: attachment; filename="document.html"');
【讨论】:
在响应标头中,将 Content-Disposition 设置为 "attachment; filename=something.html"
【讨论】:
将 HTTP 响应的 Content-Type 标头设置为“application/octet-stream”。
在 ASP.net/C# 中
Response.ContentType = "application/octet-stream";
【讨论】:
当请求该文件时,服务器需要返回不同的 MIME 类型,例如 application/octet-stream。
【讨论】: