4

According to RFC 2396,

The plus "+", dollar "$", and comma "," characters have been added to
those in the "reserved" set, since they are treated as reserved within the query component.

Indeed, search this site for "plus + comma , dollar $", and you get

https://stackoverflow.com/search?q=plus+%2B+comma+,+dollar+$

Plus is only encoded (by the application) when it's not being used as a delimiter.

But as others have observed, .NET's UrlDecode function converts plus to space. Where is this behavior specified?

4

1 回答 1

7

此行为在哪里指定?

奇怪的是, HTML规范。

UrlDecode是一种误导性的命名。

+仅代表application/x-www-form-urlencodedHTML 定义的数据中的空格;也就是说,无论是在表单 POST 提交请求正文中还是在?queryURL 的一部分中。这是一个特例!在 URL 的其他地方,加号就是加号。

http://www.example.com/path+path/x?query+name=query+value

在此 URL 中,参数query name设置为query value。它可以通过在 GET 表单中提交此表单字段来生成:

<input name="query name" value="query value">

但是,文件夹名称的字面意思是path+path. 没有空间。

因为这令人困惑且可能模棱两可,所以最好的方法总是将空格编码为%20. 您可以使用UrlPathEncode在 .NET 中执行此操作。这在 URL 的查询部分和路径中同样有效。

于 2010-04-23T18:20:28.527 回答