加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 为什么HttpUtility.UrlPathEncode标记为“不使用”?

发布时间:2020-12-16 04:24:10 所属栏目:asp.Net 来源:网络整理
导读:为什么.NET for HttpUtility.UrlPathEncode for .NET 4.5的文档说明 Do not use; intended only for browser compatibility. Use UrlEncode. UrlEncode不会这样做,它为URL的参数部分编码字符串,而不是路径部分.有没有更好的方法来编码路径部分的字符串,为什
为什么.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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读