为什么.NET for
HttpUtility.UrlPathEncode for .NET 4.5的文档说明
Do not use; intended only for browser compatibility. Use UrlEncode.
UrlEncode不会这样做,它为URL的参数部分编码字符串,而不是路径部分.有没有更好的方法来编码路径部分的字符串,为什么我不应该使用这个函数,这是在1.1以后的框架中工作?
解决方法
基于
MSDN,他们建议使用UrlEncode来承认它适用于所有平台和浏览器
You can encode a URL using with the UrlEncode method or the UrlPathEncode method. However,the methods return different results. The UrlEncode method converts each space character to a plus character (+). The UrlPathEncode method converts each space character into the string “%20”,which represents a space in hexadecimal notation. Use the UrlPathEncode method when you encode the path portion of a URL in order to guarantee a consistent decoded URL,regardless of which platform or browser performs the decoding.
UrlEncode也使用UTF-8编码,因此如果您使用不同语言(如阿拉伯语)发送查询字符串,则应使用UrlEncode