利用HttpWebRequest Post数据 中文编程乱码
postrequest.Method = "POST";
//postrequest.Referer = "http://www.baidu.com";
postrequest.Accept = @"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
//postrequest.KeepAlive = true;
postrequest.ContentType = "application/x-www-form-urlencoded";//Post所有
postrequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)";
postrequest.CookieContainer = cc;
string pd = "ct=" + ct + "&tn=baiduSubmitThread&word=" + tbname + "&lm=" + lm + "&z=0&sc=0&cm=0&bs=" + bs + "&str2="+ str2 +"&str3=" + str3 + "&str4=" + str4 + "&bu=http://post.baidu.com/f?kw=" + tbname + "&ti=" + subject + "&co=" + context + "&str1=http%3A%2F%2F&ch1=on&Submit3=%B7%A2%B1%ED%CC%F9%D7%D3";
byte[] PostData = System.Text.Encoding.ASCII.GetBytes(pd);
postrequest.ContentLength = PostData.Length;//设定请求字节的长度
Stream smp = postrequest.GetRequestStream();//得到请求流
smp.Write(PostData, 0, PostData.Length);//写入请求流
smp.Close();//关闭流
response = (HttpWebResponse)postrequest.GetResponse();//得到请求流
using (Stream sm = response.GetResponseStream())//得到响应流
{
using (StreamReader sr = new StreamReader(sm, System.Text.Encoding.Default))
{
string strResult = sr.ReadToEnd();//把服务器返回的结果赋值给字符串
response.Close();//关闭响应流
if (strResult.IndexOf("操作成功") > 1)
{
return true;
}
else
{
return false;
}
}
}
这段post数据的程序,其中subject 和 context 两个变量都是中文,post服务器后,页面现实的都是????