I am fetching the byte array using Spring Framework RestTemplate
.
But I also need to fetch the media type of the fetched result.
The media type of this byte array can be of any type.
The code used now for fetching bytes is below.
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.valueOf("application/pdf")));
ResponseEntity<byte[]> result = restTemp.exchange(
url,
HttpMethod.GET,
entity,
byte[].class,
documentId
);
The above code will fetch only PDF content type.
So I have the following questions:
- How to set the content type to accept any generic media type because the service at the other end is providing any random media type for the byte array?
- Could someone please suggest how the media type can be fetched?
Any suggestions are welcome.