URL encoding the space character: + or ?

后端 未结 4 2020
迷失自我
迷失自我 2020-11-22 02:00

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

4条回答
  •  忘了有多久
    2020-11-22 02:36

    From Wikipedia (emphasis and link added):

    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.

    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 ?.

提交回复
热议问题