我用WebRequest从客户端获得指定页面的代码,生成静态页,可是现在问题来了生成的汉字全是乱码,我该怎么做呀???我已经把web.config的<?xml version="1.0" encoding="GB2312" ?>修改了
把
<globalization
requestEncoding="GB2312"
responseEncoding="GB2312"
/>这个地方也修改了.还是有问题下面是这段代码:请高人指点一下
private void Button1_Click(object sender, System.EventArgs e)
{
System.Net.WebRequest HttpWebRequest=System.Net.WebRequest.Create("http://www.********.com/web/index.aspx");
System.Net.WebResponse HttpWebResponse =HttpWebRequest.GetResponse();
System.IO.StreamReader sr=new System.IO.StreamReader(HttpWebResponse.GetResponseStream(),System.Text.Encoding.GetEncoding("GB2312")); string ffname = Server.MapPath("//web") +"//index.htm";
string txthtm=sr.ReadToEnd();
//this.TextBox1.Text= sr.ReadToEnd();
//创建文件信息对象
FileInfo finfo = new FileInfo(ffname);
//以打开或者写入的形式创建文件流
using(FileStream fs = finfo.OpenWrite())
{
//根据上面创建的文件流创建写数据流
StreamWriter sw = new StreamWriter(fs,System.Text.Encoding.GetEncoding("GB2312"));
//把新的内容写到创建的HTML页面中
sw.WriteLine(txthtm);
sw.Flush();
sw.Close();
}
}
把
<globalization
requestEncoding="GB2312"
responseEncoding="GB2312"
/>这个地方也修改了.还是有问题下面是这段代码:请高人指点一下
private void Button1_Click(object sender, System.EventArgs e)
{
System.Net.WebRequest HttpWebRequest=System.Net.WebRequest.Create("http://www.********.com/web/index.aspx");
System.Net.WebResponse HttpWebResponse =HttpWebRequest.GetResponse();
System.IO.StreamReader sr=new System.IO.StreamReader(HttpWebResponse.GetResponseStream(),System.Text.Encoding.GetEncoding("GB2312")); string ffname = Server.MapPath("//web") +"//index.htm";
string txthtm=sr.ReadToEnd();
//this.TextBox1.Text= sr.ReadToEnd();
//创建文件信息对象
FileInfo finfo = new FileInfo(ffname);
//以打开或者写入的形式创建文件流
using(FileStream fs = finfo.OpenWrite())
{
//根据上面创建的文件流创建写数据流
StreamWriter sw = new StreamWriter(fs,System.Text.Encoding.GetEncoding("GB2312"));
//把新的内容写到创建的HTML页面中
sw.WriteLine(txthtm);
sw.Flush();
sw.Close();
}
}
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">