为什么逗号URL被编码?

Sco*_*tes 26 forms asp.net-mvc urlencode query-string

在ASP.NET MVC中调试时,我没有看到以下区别:

http://mysite.com?q=hi,bye
Run Code Online (Sandbox Code Playgroud)

http://mysite.com?q=hi%2Cbye
Run Code Online (Sandbox Code Playgroud)

查询字符串参数"q"的值始终为"hi,bye".

那么为什么逗号编码?

我想做这样的事情/sf/answers/52647661/.

我有这样的形式:

<form method="GET" action="/Search">
     <input type="hidden" name="q" value="hi,bye"/>
     <input type="submit" value="ok"/>
</form>
Run Code Online (Sandbox Code Playgroud)

如何防止此值被编码?

Kyl*_*nes 19

URI规范RFC 3986指定URI路径组件不包含未编码的保留字符,逗号是保留字符之一.对于逗号之类的逗号,将其保留为未编码的风险,该角色将被视为URI方案中的分隔符语法.百分比编码保证字符将作为数据传递.

  • 在这个问题中,逗号不在URI路径组件中,而是在URI查询组件中,根据RFC 3986,它可能包含子语句,其中包括逗号. (33认同)
  • 如果我正确阅读规范:`path = path-absolute` =&gt; `path-absolute = "/" [ segment-nz *( "/" segment ) ]` =&gt; `segment = *pchar` =&gt; `pchar = 未保留 / pct 编码 / 子 delims / ":" / "@"` =&gt; `sub-delims = "!" / "$" / "&amp;" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="`。因此,逗号在 URI 段、查询或片段中是有效的。 (2认同)

Ale*_*lex 8

我发现这个不需要 URL编码的字符列表:http://web.archive.org/web/20131212154213/http: //urldecoderonline.com/url-allowed-characters.htm

更新
自原始链接中断后,我使用archive.org从2013年12月的页面中获取以下文本

允许的URL字符列表

未保留 - 可以编码但不是必需的

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m n o p q r s t u v w x y z
0 1 2 3 4 5 6 7 8 9 - _ . ~
Run Code Online (Sandbox Code Playgroud)

保留 - 有时必须编码

! * ' ( ) ; : @ & = + $ , / ? % # [ ]
Run Code Online (Sandbox Code Playgroud)

  • 不再有效,页面被广告网站取代. (2认同)