简体   繁体   中英

Spring restTemplate not working for single quotes in URL. Works with postman

Simple restTemplate exchange used for a GET request.

Header information

HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.ALL));
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
headers.add("Authorization",  ************);

URL:

/api/odata/GetAvailableObjects?fromTime=datetime'2018-02-02T12:00:00'&$format=json&toTime=datetime'2018-02-10T12:00:00'

I tried building this URL with either MessageFormat.format or URIBuilder . The single quotes are the problem. So far I tried double-ing them, escaping them or leaving them as they are.

I enabled some extra logging with : logging.level.org.springframework.web.client.RestTemplate=DEBUG This displays the URL.. if I copy that URL and paste it in POSTMAN, I receive results, from spring I receive 400 Bad request.

I suppose it might be some additional encoding to blame. Any ideas?

  • The JWT had way to many scopes, the server API decided to throw a 400 without any message and the server logs were not available..
  • A flag in application.properties that sets the maximum header size.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM