The default URL encoding of the FromBody parameter uses a non-strict mode, which will encode spaces as %20, but now some applications no longer recognize %20 as spaces, which will cause decoding errors.
I think the default encoding mode should be changed to strict mode, and spaces should be encoded as +.
Can you cite a spec? I believe only %20 is valid for form bodies.
I don’t know which development language is used by the service I requested and how to decode the URL, but the data I sent can be decoded correctly only when spaces are encoded as +, but httpclient does encode spaces as +.
And I also saw the description of the encoding of spaces in Wikipedia, the encoding of spaces should use + instead of %20.
wikipedia
The encoding used by default is based on an 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.
Is the spec now https://url.spec.whatwg.org/#urlencoded-serializing
It seems that the W3C recommendation is also "+": http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1
In jdk, URLEncoder will encode most special characters, such as spaces, %, +, #, etc., but OKhttp does not encode these characters.
I would recommend to percent-encode all character except "unreserved" defined in RFC-3986, p.2.3
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
Yep, you're absolutely right. How'd we get that wrong?! Can fix.
The spec we should follow here is W3’s.
https://www.w3.org/TR/2014/REC-html5-20141028/single-page.html#url-encoded-form-data
Yep, you're absolutely right. How'd we get that wrong?! Can fix.
I have also encountered this problem and hope it can be solved as soon as possible
@swankjesse Is this a good one for an external contributor to submit a PR?
Let’s just do it. It isn’t very big!
Let’s just do it. It isn’t very big!
Has this problem not been fixed yet?
@swankjesse Is this a good one for an external contributor to submit a PR?
Has this problem not been fixed yet?
No, but we also don't have an imminent release it would go out with.
Hi @swankjesse & @yschimke, is it okay that I can contribute with my PR to fix the bug?
@emrecosar yep - I can review. Sorry we didn't submit a PR for it, although we haven't had a release since then.