在URL中,是否应使用%20或+对空格进行编码? [英] In a URL, should spaces be encoded using %20 or +?
问题描述
在URL中,我应该使用%20
还是+
对空格进行编码?例如,在下面的示例中,哪个是正确的?
In a URL, should I encode the spaces using %20
or +
? For example, in the following example, which one is correct?
www.mydomain.com?type=xbox%20360
www.mydomain.com?type=xbox+360
我们的公司倾向于前者,但是使用Java方法(和"UTF-8"
)返回后者.
Our company is leaning to the former, but using the Java method URLEncoder.encode(String, String)
with "xbox 360"
(and "UTF-8"
) returns the latter.
那么,有什么区别?
推荐答案
表单数据(用于GET或POST)通常编码为application/x-www-form-urlencoded
:这将+
指定为空格.
Form data (for GET or POST) is usually encoded as application/x-www-form-urlencoded
: this specifies +
for spaces.
URL编码为 RFC 1738 ,其中指定了%20
.
URLs are encoded as RFC 1738 which specifies %20
.
从理论上讲,我认为您应该在?
之前加上%20,然后在之后加上+:
In theory I think you should have %20 before the ?
and + after:
example.com/foo%20bar?foo+bar
这篇关于在URL中,是否应使用%20或+对空格进行编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!