Use RestTemplate.execute
instead, which allows you to attach a ResponseExtractor
, in which you have access to the response body
which an InputStream
, we take that InputStream
and write it to a file
restTemplate.execute(
url,
HttpMethod.GET,
request -> {},
response -> {
//get response body as inputstream
InputStream in = response.getBody();
//write inputstream to a local file
Files.copy(in, Paths.get("C:/path/to/file.wav"), StandardCopyOption.REPLACE_EXISTING);
return null;
}
);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…