I have a weird problem with urlencoding a plus sign +as a request parameter for an API request. The API documentation states:
The date must be in W3C format, for example .. '2016-10-24T13: 33: 23 + 02: 00'
So far, so good, so I use this code (minimized) to generate the URL using Spring UriComponentBuilder:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX");
ZonedDateTime dateTime = ZonedDateTime.now().minusDays(1);
String formated = dateTime.format(formatter);
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(baseUrl);
uriComponentsBuilder.queryParam("update", formated);
uriComponentsBuilder.build();
String url = uriComponentsBuilder.toUriString();
An uncoded request will look like this:
https:
The encoded string results in:
https://example.com?update=2017-01-05T12:40:44%2B01
which is (IMHO) a correctly encoded String request. See the %2Breplacement +at +01the end of the query string.
Now, when I send a request against the API using an encoded URL, I get an error when the request cannot be processed.
, , %2B + , :
url.replaceAll("%2B", "+");
, + whitespace. , URL-, ,
https:
UPDATE:
RFC 3986 ( 3.4) + .
3.4.
, ( 3.3), URI
( ).
mark ( "?" ) ( "#" )
URI.
Berners-Lee, et al. [ 23] RFC 3986 URI
2005 .
query = *( pchar / "/" / "?" )
( "/" ) ( "?" ) . , , , URI ( 5.1), , , . ,
" = " - URI, . .
qaru.site/questions/378614/..., Spring UriComponentBuilder , , , . , : UriComponentBuilder ?