使用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();
        }
原文地址:https://www.cnblogs.com/chenjunbiao/p/1760260.html