• 使用WebClient后的Response编码的问题


    使用WebClient可以抓取别的网页的内容,然后提供下载,但是使用Response输出时要注意编码问题,否则打开是一片空白。使如:
            protected override void Render(HtmlTextWriter writer)
            
    {
                
    string url = string.Format("{0}/con001_projectmanage/job/downloadresume.aspx?resumeid={1}",
                    Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery,
    string.Empty).TrimEnd('/').ToLower(),
                    Request.QueryString[
    "resumeid"]);

                WebClient wb 
    = new WebClient();
                
    byte[] buf = wb.DownloadData(url);//从指定的Uri获取数据
                
                Page.Response.Clear();
                Response.Charset 
    = "UTF-8";        //TODO:指定的Charset要与ContentEncoding相一致。
                Page.Response.ContentType = "text/html";
                Page.Response.AddHeader(
    "content-disposition""attachment; filename=\"resume.htm\""); 
                Page.Response.ContentEncoding 
    = Encoding.UTF8;
                Page.Response.OutputStream.Write(buf, 
    0, buf.Length);
                Page.Response.Flush();
                Page.Response.End();
            }
  • 相关阅读:
    VINS_Fusion IMU数据处理过程
    SLIC聚类算法
    视觉SLAM十四讲(第二版)第五讲笔记
    视觉SLAM十四讲(第二版)第四讲笔记
    视觉SLAM十四讲(第二版)第三章笔记
    g++命令总结
    第二次冲刺第一天
    11月21日
    11月20日
    11月19日
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/1760260.html
Copyright © 2020-2023  润新知