java.net.URLEncoder
will encode a single whitespace with +
.
scala> val encodedSpace = URLEncoder.encode(" ", "UTF-8")
encodedSpace: String = +
However, per this W-3 doc, shouldn't it be encoded with %20
?
java.net.URLEncoder
will encode a single whitespace with +
.
scala> val encodedSpace = URLEncoder.encode(" ", "UTF-8")
encodedSpace: String = +
However, per this W-3 doc, shouldn't it be encoded with %20
?
From the DOCS (http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4):
application/x-www-form-urlencoded
This is the default content type. Forms submitted with this content type must be encoded as follows:
Control names and values are escaped. Space characters are replaced
by +', and then reserved characters are escaped as described in
[RFC1738], section 2.2: Non-alphanumeric characters are replaced by
%HH', a percent sign and two hexadecimal digits representing the
ASCII code of the character. Line breaks are represented as "CR LF"
pairs (i.e., `%0D%0A').
The control names/values are listed in the order they appear in the
document. The name is separated from the value by =' and name/value
pairs are separated from each other by
&'.
You have to replace it from +
to %20
. The prior is a default behavior.
For example:
System.out.println(java.net.URLEncoder.encode(" ", "UTF-8").replace("+", "%20"));
The above is the typical case of application/x-www-form-urlencoded.
multipart/form-data
uses MIME encoding
.
application/x-www-form-urlencoded
uses +
.
Properly encoded URIs
use %20
.
http://www.bing.com/search?q=hello+world
http://camera.phor.net/cameralife/folders/2012/2012-06%20Pool%20party/