resteTemplate in url% if the band is to be escaped as 25%, not the right to access resources
For example: https: //xxx.xxx.xx sig = Tr5VnQ1enApvTxZJxsr99Bb5m% 2BhM1% 2FpSxXUOrmAVjN8% 3D?
It will be converted to: https: //xxx.xxx.xx sig = Tr5VnQ1enApvTxZJxsr99Bb5m% 252BhM1% 252FpSxXUOrmAVjN8% 253D?
Solution :
The String url parameter into the URI parameter:
Sample code:
String url = "https://xxx.xxx.xx?sig=Tr5VnQ1enApvTxZJxsr99Bb5m%2BhM1%2FpSxXUOrmAVjN8%3D"; try { // The String url into the URI object Are you new = ON (url); HttpHeaders header = new HttpHeaders(); Object o = restTemplate.exchange( url, HttpMethod.GET, new HttpEntity<String>(header), String.class); } catch (URISyntaxException e) { e.printStackTrace (); }
By
URI uri = new URI (url)
; problem solved
Cause Analysis:
RestTemplate to the exchange method, for example, other getForObject, getForEntity, postForObject and so is the same,
If the parameter is of type String url, excute before sending the request, it will first type String url into url URI type, that is, conversion errors occur in this process.
Source as follows:
String url need to be converted to the type of URI
URI type url will be directly executed