zoukankan      html  css  js  c++  java
  • 使用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();
            }
  • 相关阅读:
    python之新手一看就懂的小说爬虫
    Mysql与Oracle区别
    Java面试2018常考题目汇总(一)(转)
    单例式的优缺点和使用场景
    设计模式之单例模式通俗理解
    IntelliJ Idea 最常用快捷键
    sql语句基础和提升
    Tomcat 安装配置
    Git基本常用命令
    Java练手题
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/1760260.html
Copyright © 2011-2022 走看看