Server.UrlEncode("My File.doc") 返回"My+File.doc",而javascript escape("My File.doc") 返回"My%20File.doc"。据我了解,javascript 是 corectly URL 编码字符串,而 .net 方法不是。在练习放置 http://somesite/My+File.doc 时,它似乎确实是这样工作的在我可以使用 firefox/即测试的任何情况下都不会获取“我的 File.doc”和 IIS,而 http://somesite/My%20File.doc工作良好。我是不是遗漏了什么或者 Server.UrlEncode 是否无法正常工作?
最佳答案
使用 Javascripts encodeURIComponent()/decodeURIComponent() 用于使用 .Net 的 URLEncode/URLDecode 进行“往返”编码。
编辑
据我所知,历史上“+”在 URL 编码中用作空格字符 (ASCII 20) 的特殊替代。如果实现不将空格视为具有“+”替换的特殊字符,那么它仍然必须使用其 ASCII 代码(因此为“%20”)对其进行转义。
在 http://bytes.com/topic/php/answers/5624-urlencode-vs-rawurlencode 上对情况进行了非常好的讨论。 .顺便说一句,这是不确定的。 RFC 2396 将空格与其他字符混为一谈,没有未保留的表示形式,这与“%20”人群有关。
RFC 1630 支持“+”人群(通过论坛讨论)...
Within the query string, the plus sign is reserved as shorthand notation for a space. Therefore, real plus signs must beencoded. This method was used to make query URIs easier to pass in systems which did not allow spaces.
此外,核心 RFC 是...
RFC 1630 - WWW 中的通用资源标识符
RFC 1738 - 统一资源定位符 (URL)
RFC 2396 - 统一资源标识符 (URI):通用语法
关于c# - Server.UrlEncode(string s)... 没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2516266/