URL编码报价和空间
我有一个是带JavaScript的codeD某些查询的文字,但我已经遇到了一个使用案例,我可能要带code在服务器端相同的文字,编码这是发生不一样。我需要它是相同的。下面是一个例子。
I have some query text that is being encoded with JavaScript, but I've encountered a use case where I might have to encode the same text on the server side, and the encoding that's happening is not the same. I need it to be the same. Here's an example.
我输入我最喜欢的食物
在搜索框中,并击中了搜索
按钮。 JavaScript的EN codeS这是%22I%20like%20food%22
I enter "I like food"
into the search box and hit the search
button. JavaScript encodes this as %22I%20like%20food%22
比方说,我得到了相同的值,在服务器端的请求对象的字符串。它看起来像这样:\\我喜欢的食物\\
Let's say I get the same value as a string on a request object on the server side. It will look like this: "\"I like food\""
当我使用 HttpUtility.UrlEn code(值)
,结果是%22I + +一样的食物22%
。如果我使用 HttpUtility.UrlPathEn code(值)
,结果是\\I%20like%20food \\
When I use HttpUtility.UrlEncode(value)
, the result is "%22I+like+food%22"
. If I use HttpUtility.UrlPathEncode(value)
, the result is "\"I%20like%20food\""
所以 UrlEn code
编码是我的引号,但使用的是 +
字符空格。 UrlPathEn code
编码是我的空间,但不是我的编码转义引号。
So UrlEncode
is encoding my quotes but is using the +
character for spaces. UrlPathEncode
is encoding my spaces but is not encoding my escaped quotes.
我真的需要它做两件事,否则搜索code对我彻底borks(我有在搜索code无控制)。
I really need it to do both, otherwise the Search code completely borks on me (and I have no control over the search code).
提示?
UrlPathEn code
不逃避,因为它们不需要路径组件进行转义。
UrlPathEncode
doesn't escape "
because they don't need to be escaped in path components.
Uri.EscapeDataString$c$c>应该做你想做的。
Uri.EscapeDataString
should do what you want.