[英]How to use RestTemplate with application/octet-stream response type
[英]How to save and display a json/octet-stream response from a server in spring boot REST service?
这是我正在使用的代码:
RestTemplate restTemplate = new RestTemplate();
String fooResourceUrl = "server URI";
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
String auth = "username:password";
byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(Charset.forName("US-ASCII")) );
String authHeader = "Basic " + new String( encodedAuth );
HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);
restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor("username", "password"));
ResponseEntity<String> result = restTemplate.exchange(fooResourceUrl, HttpMethod.GET, entity, String.class);
System.out.println(result);
已解决::仅返回“结果”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.