The RestTemplate.exchange()
will encode all the invalid characters in URL but not +
as +
is a valid URL character. But how to pass a +
in any URL's query parameter?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
If the URI you pass to the RestTemplate has encoded set as true then it will not perform the encoding on the URI you pass else it will do.
So if you need to pass a query param with
+
in it then the RestTemplate will not encode the+
but every other invalid URL character as+
is a valid URL character. Hence you have to first encode the param (URLEncoder.encode("abc+123=", "UTF-8")
) and then pass the encoded param to RestTemplate stating that the URI is already encoded usingbuilder.build(true).toUri();
, wheretrue
tells the RestTemplate that the URI is alrady encoded so not to encode again and hence the+
will be passed as%2B
.builder.build(true).toUri();
OUTPUT : http://example.com/endpoint?param1=abc%2B123%3D as the encoding will be perfromed once.builder.build().toUri();
OUTPUT : http://example.com/endpoint?param1=abc%252B123%253D as the encoding will be perfromed twice.