java- apache http client v4.x- how to extract different elements of response from HTTPResponse object

StackOverflow https://stackoverflow.com/questions/9053122

  •  04-12-2019
  •  | 
  •  

Question

I am working with the Apache HTTP Client and trying to extract content from the response...

I have the response in a HTTP Response object named 'response'.

Now, how do I extract the following from the HTTPResponse object??--

(1) Response content as byte[] (2) Content length (3) Mime type (4) Charset

Was it helpful?

Solution

HttpEntity entity = response.getEntity();
InputStream instream = entity.getContent();
instream.read();

That's the main codes. You can see the examples in:httpcomponents-client-4.1.3\examples\org\apache\http\examples\client

OTHER TIPS

You need to get HttpEntity and do getContentLenght() and getContentType();. Here is apache tutorial

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top