C# http post 中文乱码问题

request.ContentType = "application/json; charset=utf-8";

 

这种的postdata 在写入 Stream的时候要确保编码是  utf-8

 

                string postData = "中文乱码问题";
                UTF8Encoding encoding = new UTF8Encoding();
                byte[] bytepostData = encoding.GetBytes(postData);
                request.ContentLength = bytepostData.Length;
                //发送数据 using结束代码段释放
                using (Stream requestStm = request.GetRequestStream())
                {
                    requestStm.Write(bytepostData, 0, bytepostData.Length);
                }

  

posted @ 2020-05-09 11:56  来了啊老弟  阅读(4167)  评论(0编辑  收藏  举报