[英]Spring restTemplate not working for single quotes in URL. Works with postman
Simple restTemplate exchange used for a GET request.用于 GET 请求的简单 restTemplate 交换。
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
.我尝试使用
MessageFormat.format
或URIBuilder
构建此 URL。 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.我启用了一些额外的日志记录: logging.level.org.springframework.web.client.RestTemplate=DEBUG 这会显示 URL .. 如果我复制该 URL 并将其粘贴到 POSTMAN 中,我会收到结果,从 spring 我收到 400 Bad request .
I suppose it might be some additional encoding to blame.我想这可能是一些额外的编码。 Any ideas?
有什么想法吗?
application.properties
that sets the maximum header size. application.properties
中的一个标志,用于设置最大标头大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.