C#post提交带有特殊符号的数据老是出错
static public string sjpost(string get,string cs,ref string sRtn)/*POST数据发送函数*/
{
WebResponse res = null;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(get);/*数据发送地址*/
request.Method = "post";
request.KeepAlive = true;
request.UserAgent = "User-Agent Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";//浏览器信息
request.ContentType = "application/x-www-form-urlencoded";
//postdata= System.Web.HttpUtility.UrlEncode(cs, Encoding.GetEncoding("gb2312"));
//byte[] postdata = Encoding.GetEncoding("gb2312").GetBytes(cs);
//byte[] postdata = Encoding.GetEncoding("UTF-8").GetBytes(cs);
byte[] postdata = Encoding.ASCII.GetBytes(cs);/*发送数据*/
request.ContentLength = postdata.Length;
Stream postStream = request.GetRequestStream();
postStream.Write(postdata, 0, postdata.Length);
postStream.Close();
res = request.GetResponse() as HttpWebResponse;
Encoding encode = Encoding.GetEncoding("UTF-8");
StreamReader stmR = new StreamReader(res.GetResponseStream(), encode);
sRtn = stmR.ReadToEnd();
return sRtn;
}
上面是我的代码,我提交类似id=user&password=password&code=code&site=asiabsi&page=default&lang=zh-cn&key=27676654330793&tea=776493&tzDiff=0&sv=B14 这类格式的数据的时候老是提示出错,无法实现网站登录,请高手指点下到底是为什么??