gpt4 book ai didi

asp.net - HttpServerUtility.UrlPathEncode 与 HttpServerUtility.UrlEncode

转载 作者:行者123 更新时间:2023-12-03 11:35:07 24 4
gpt4 key购买 nike

HttpServerUtility.UrlPathEncode有什么区别和 HttpServerUtility.UrlEncode ?我什么时候应该选择一个?

最佳答案

更新:从 4.5 开始,根据 MSDN 引用,Microsoft 建议仅使用 UrlEncode。此外,先前在 MSDN 中列出的信息并未完全描述这两种方法的行为 - 请参阅注释。

区别在于空间转义 - UrlEncode 将它们转义为 + 符号,UrlPathEncode 将它们转义为 %20。 + 和 %20 仅当它们是 QueryString 部分的一部分时才等效 per W3C .所以你不能使用 + 号转义整个 URL,只有查询字符串部分。底线是 UrlPathEncode 总是更好 imho

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.

http://msdn.microsoft.com/en-us/library/4fkewx0t.aspx

关于asp.net - HttpServerUtility.UrlPathEncode 与 HttpServerUtility.UrlEncode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4145823/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com