高手请指点HttpWebRequest乱码问题!急啊~
大川川- 2007-05-09 11:36:43 我在向站点发送请求时,只要有中文就乱码!
string strData = "";
Encoding encoding = Encoding.GetEncoding("GB2312");
byte[] data = encoding.GetBytes( strPostData );
// 准备请求...
try
{
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl);
myRequest.Method = "POST";
myRequest.Timeout = 60000;
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// 发送数据
newStream.Write(data, 0, data.Length);
newStream.Close();
//得到网页的原文件
HttpWebResponse response = ( HttpWebResponse )myRequest.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader( resStream, System.Text.Encoding.UTF8 );
strData = sr.ReadToEnd();
resStream.Close();
sr.Close();
response.Close();
}
catch ( Exception ex )
{
Response.Write( ex.Message );
}
return strData ;