标题:根据Url地址生成静态页完成后中文出现乱码是怎么回事呀
只看楼主
ycbbg
Rank: 1
来 自:江西
等 级:新手上路
帖 子:99
专家分:0
注 册:2007-11-26
结帖率:100%
 问题点数:0 回复次数:1 
根据Url地址生成静态页完成后中文出现乱码是怎么回事呀
//根据Url地址生成静态页保持
        protected void Button2_Click(object sender, EventArgs e)
        {
            Encoding code = Encoding.GetEncoding("utf-8");
            StreamReader sr = null;
            StreamWriter sw = null;
            string str = null;

            //读取远程路径
            WebRequest temp = WebRequest.Create(txtUrl.Text.Trim());
            WebResponse myTemp = temp.GetResponse();
            sr = new StreamReader(myTemp.GetResponseStream(), code);
            //读取
            try
            {
                sr = new StreamReader(myTemp.GetResponseStream(), code);
                str = sr.ReadToEnd();

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                sr.Close();
            }
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".htm";

            //写入
            try
            {
                sw = new StreamWriter(Server.MapPath("htm/") + fileName, false, code);
                sw.Write(str);
                sw.Flush();

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                sw.Close();
                Response.Write("恭喜<a href=htm/" + fileName + " target=_blank>" + fileName + "</a>已经生成,保存在htm文件夹下!");
            }

        }
    }
搜索更多相关主题的帖子: 静态 乱码 Url 中文 地址 
2008-09-07 17:04
雨夜·路人
Rank: 1
等 级:新手上路
威 望:1
帖 子:79
专家分:0
注 册:2008-8-27
得分:0 
Encoding code = Encoding.GetEncoding("utf-8");
用gb2312吧
2008-09-07 22:52



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-231974-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013585 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved