URLEncoder.encode() and a whitespace?

后端 未结 3 1327
庸人自扰
庸人自扰 2021-01-22 14:43

I\'ve got a resource on my server named:

some image.png

There\'s a space in the name. When I type the url into the browser (chrome), it\'s tran

3条回答
  •  伪装坚强ぢ
    2021-01-22 14:46

    IIRC, both + and %20 are valid strings in a URL.

    In the path part of the URL + is not reserved[1], and so has no special meaning and does not need to be %-encoded. Therefore, + means literally the + character in the path part of the URL.

    In the query part of the URL + is reserved[2], although the purpose is not stated.

    However, when using HTML forms the MIME encoding application/x-www-form-urlencoded is used to encode the parameters which (in a HTTP GET request) are included in the query part of the URL[3].

    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". [3]

    Sources:

    http://www.ietf.org/rfc/rfc2396.txt

    [1] Section 3.3

    [2] Section 3.4

    http://en.wikipedia.org/wiki/Percent-encoding

    [3] "The application/x-www-form-urlencoded type"

提交回复
热议问题