在 URL 中,空格应该使用 %20 还是 + 进行编码? [英] In a URL, should spaces be encoded using %20 or +?

查看:33
本文介绍了在 URL 中,空格应该使用 %20 还是 + 进行编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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方法URLEncoder.encode(String, String) with "xbox 360" (和 "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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆