c# wpf 服务器端接受post请求 中文乱码问题

最近做项目时遇到的一个问题,根据百度到的方法以UTF-8解码后,依旧是乱码。

之后发现了System.Web里的HttpUtility.UrlDecode函数,成功将乱码转换回中文。


HttpUtility.UrlDecode用法:

//读取请求流
Stream stream = request.InputStream;  
StreamReader streamReader = new StreamReader(stream);  

string s = streamReader.ReadLine();  //如果有中文,字符串s这里会有乱码
 
string ss = HttpUtility.UrlDecode(s);  //处理后乱码恢复成中文

注意需要添加System.Web的引用,并且需要添加System.Web.dll

using System.Web;


猜你喜欢

转载自blog.csdn.net/qq_40993793/article/details/80140469