编码空格字符的URL:+或%20? [英] URL encoding the space character: + or %20?

查看:136
本文介绍了编码空格字符的URL:+或%20?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

URL中的空格何时编码为+,何时编码为%20?

When is a space in a URL encoded to +, and when is it encoded to %20?

推荐答案

来自维基百科(强调并添加了链接):

From Wikipedia (emphasis and link added):

提交已输入到HTML表单中的数据时,将使用GET或POST方法或者历史上通过电子邮件以HTTP请求消息的形式对表单字段名称和值进行编码并发送到服务器. 默认情况下使用的编码基于URI常规通用百分比编码规则的早期版本,带有 MIME类型的数据以这种方式编码是application/x-www-form-urlencoded,目前是在HTML和XForms规范中定义的(仍然以非常过时的方式).

When data that has been entered into HTML forms is submitted, the form field names and values are encoded and sent to the server in an HTTP request message using method GET or POST, or, historically, via email. The encoding used by default is based on a very early version of the general URI percent-encoding rules, with a number of modifications such as newline normalization and replacing spaces with "+" instead of "%20". The MIME type of data encoded this way is application/x-www-form-urlencoded, and it is currently defined (still in a very outdated manner) in the HTML and XForms specifications.

因此, real 百分比编码使用%20,而URL中的表单数据是使用+的修改形式.因此,您最有可能只在?之后的查询字符串中的URL中看到+.

So, the real percent encoding uses %20 while form data in URLs is in a modified form that uses +. So you're most likely to only see + in URLs in the query string after an ?.

这篇关于编码空格字符的URL:+或%20?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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