这几天遇到一个url中汉字编码的问题,经过研究发现
.net的HttpWebRequest在发送url中,会把url中的汉字自动编码WebRequest req = HttpWebRequest.Create( "http://localhost/WebTest/Server.aspx?China=汉字 ");URL 被C#自动编码了。http://localhost/WebTest/Server.aspx?China=汉字变成了: http://localhost/WebTest/Server.aspx?China=%e6%b1%89%e5%ad%97
我想解决问题的方式就是不让HttpWebRequest自动编码
.net的HttpWebRequest在发送url中,会把url中的汉字自动编码WebRequest req = HttpWebRequest.Create( "http://localhost/WebTest/Server.aspx?China=汉字 ");URL 被C#自动编码了。http://localhost/WebTest/Server.aspx?China=汉字变成了: http://localhost/WebTest/Server.aspx?China=%e6%b1%89%e5%ad%97
我想解决问题的方式就是不让HttpWebRequest自动编码
但是用在HttpWebRequest里面用,就自动编码,服务器端接收就出现问题了
WebRequest req = HttpWebRequest.Create( "http://localhost/WebTest/Server.aspx?China=" + System.Web.HttpUtility.UrlEncode("汉字", System.Text.UnicodeEncoding.GetEncoding("GB2312")));