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();
            }
  • 相关阅读:
    package.json中 npm依赖包版本前的符号的意义
    移动端1px的border
    react下将输入的汉字转化为拼音
    h5打开App的方法。
    图片在缩放截取后以固定尺寸上传到第三方
    图片裁切,上传,自动匹配颜色。
    ReactNative学习一
    MySQL数据库8(二)MySQL基本介绍
    MySQL数据库8(一)SQL简介

  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/1760260.html
Copyright © 2011-2022 走看看