0

Now I know what's an http entity. But what's entity used for?

I mean, when an application manipulates an http request or response, it just need to know how to parse message head and message body. Then what's the role of an entity? They have almost similar structures.

Community
  • 1
  • 1
Anderson
  • 2,496
  • 1
  • 27
  • 41

1 Answers1

0

I dont really understand what you are trying to ask?

If you mean can we skip using HttpEntity in response and request at all? The answer is no! its a convention you have to follow it, that how internet works!

Quoting entities from apache documentation:

Since an entity can represent both binary and character content, it has support for character encodings (to support the latter, ie. character content).

The entity is created when the request was successful, and used to read the response.

To read the content from the entity, you can either retrieve the input stream via the HttpEntity.getContent() method, which returns an InputStream, or you can supply an output stream to the HttpEntity.writeTo(OutputStream) method, which will return once all content has been written to the given stream.

When the entity was received as a result of a response, the methods getContentType() and getContentLength() methods are for reading the common headers Content-Type and Content-Length respectively (if they are available). Since the Content-Type header can contain a character encoding for text mime-types like text/plain or text/html, the getContentEncoding() method is used to read this information. If the headers aren't available, a length of -1 will be returned, and NULL for the content-type. If the Content-Type header is available, a [Header] object will be returned.

When creating an entity for a request, this meta data has to be supplied by the creator of the entity.

Other headers from the response are read using the getHeaders() methods from the response object.

Source: http://wiki.apache.org/HttpComponents/HttpEntity

And I'm again sorry if I didn't get your question right, but hope this helps anyways.

shivam
  • 16,048
  • 3
  • 56
  • 71