gpt4 book ai didi

c# - 从服务器保存 html 文件

转载 作者:太空宇宙 更新时间:2023-11-03 22:00:42 24 4
gpt4 key购买 nike

public void SaveSofaXML(object s, EventArgs e)
{
HttpResponse response = HttpContext.Current.Response;

StreamReader streamReader = new StreamReader(
Server.MapPath("~/SentinelOperationsUI/SoFaXML.html"));
string text = streamReader.ReadToEnd();
streamReader.Close();

response.StatusCode = 200;
response.ContentEncoding = Encoding.UTF32;
response.AddHeader("content-disposition", "attachment; filename=test.html");
response.AddHeader("Content-Transfer-Encoding", "binary");
response.AddHeader("Content-Length",
response.ContentEncoding.GetByteCount(text).ToString());
response.ContentType = "application-download";
}

我认为我在正确的轨道上。但是当我尝试保存 html 文件(~100kb)时,文件永远不会完成下载。我错过了一些必需的标题吗?谢谢

最佳答案

试试这个:

 Response.AppendHeader("content-disposition", "attachment; filename=test.html");
Response.TransmitFile(Server.MapPath("~/SentinelOperationsUI/SoFaXML.html"));
Response.End();

关于c# - 从服务器保存 html 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10228688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com