标签:中文乱码 ica data 完美解决 http ade bre header 报错
HttpWebRequest
request.ContentType = "application/x-www-form-urlencoded";
request.ContentType = "application/json; encoding=utf-8";
StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.ASCII);
StreamWriter
未使用Encoding.ASCII
,改正后但是发送的消息还是中文乱码,这就很蛋疼了 public static string PostWeiXin(string Url, string postDataStr)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "POST";
//request.ContentType = "application/json; encoding=utf-8";
request.ContentType = "application/x-www-form-urlencoded";
Stream myRequestStream = request.GetRequestStream();
StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.ASCII);
myStreamWriter.Write(postDataStr);
myStreamWriter.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//response.Cookies = cookie.GetCookies(response.ResponseUri);
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return retString;
}
WebClient
完美解决 invalid openid hint 报错以及中文乱码问题HttpWebRequest
吧 public static string SendMsgWechat(string url, string content)
{
using (WebClient webClient = new WebClient())
{
webClient.Encoding = Encoding.UTF8;
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string sResponse = webClient.UploadString(url, "POST", content);
return sResponse;
}
}
【MVC__微信客服消息】发送微信客户消息 invalid openid hint 及 中文乱码
标签:中文乱码 ica data 完美解决 http ade bre header 报错
原文地址:https://www.cnblogs.com/kikyoqiang/p/12730301.html