While issuing a GET
request using Apache HTTP Client v4, how do I obtain the response media type (formally MIME type)?
Using Apache HTTP Client v3, the MIME type was obtained with:
String mimeType = response.getMimeType();
How do I get the media type using Apache HTTP Client v4?
To get content type from response you can use ContentType class.
HttpEntity entity = response.getEntity();
ContentType contentType;
if (entity != null)
contentType = ContentType.get(entity);
Using this class you can easily extract mime type:
String mimeType = contentType.getMimeType();
or charset:
Charset charset = contentType.getCharset();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With