Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find HTTP Media Type (MIME type) from response?

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?

like image 490
Arvind Avatar asked Jan 31 '12 10:01

Arvind


1 Answers

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();
like image 76
peppered Avatar answered Sep 25 '22 23:09

peppered