javascript CSharp中的encodeURIComponent
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7545622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
encodeURIComponent in c sharp
提问by Igal
I've tried to use HttpUtility.UrlEncode in order to simulate the javscript's encodeURIComponent, but had some issues (instead of getting "%20" i got "+")
我尝试使用 HttpUtility.UrlEncode 来模拟 javscript 的 encodeURIComponent,但遇到了一些问题(我得到了“+”而不是“%20”)
then I've replaced the string, but i see that the problem is not only in these two signs, in some places the encoded string (by UrlEncode) is totally different from the encoded string by using encodeURIComponent.
然后我替换了字符串,但我发现问题不仅在于这两个符号,在某些地方,编码字符串(通过 UrlEncode)与使用 encodeURIComponent 的编码字符串完全不同。
Any ideas how it can be solved ?
任何想法如何解决?
thanks.
谢谢。
回答by Nenotlep
You are looking for HttpUtility.UrlPathEncode.
您正在寻找 HttpUtility.UrlPathEncode。
See this SO question: Server.UrlEncode vs. HttpUtility.UrlEncode