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);
                }

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM