Spring REST Template for Byte Spring REST Template for Byte spring spring

Spring REST Template for Byte


Just not send the accept header to not force the server to return that content-type. This is the same as sending a wildcard */*

//HttpHeaders headers = new HttpHeaders();//headers.setAccept(Collections.singletonList(MediaType.WILDCARD));ResponseEntity<byte[]> result = restTemp.exchange(url, HttpMethod.GET, entity, byte[].class,documentId);

After this, extract the content-type from the headers of the response

 byte body[] = result.getBody(); MediaType contentType = result.getHeaders().getContentType();


You can store a media type in the HTTP headers and use - ResponseEntity.getHeaders(), for instance. or you can wrap byte array and media type into holder class.


MediaType mediaType = result.getHeaders().getContentType();