HttpClient (4.3.5)-HTTP Entity

Source: Internet
Author: User

Depending on the origin of the entity, HttpClient divides the entity into three categories:
Streamed-the entity content is generated from the stream receiving or re-running. In particular, such entities include those received from the HTTP response. Streamed entities are usually non-repeatable to read.
Self-contained-the entity content is present in memory or obtained through a separate connection or other entity. Self-contained entities are repeatable to read. Such entities are often used for HTTP requests in entity encapsulation.
Wrapping-Entity content is obtained from other entities.
This difference is important for connection management when you get streaming content from an HTTP response. The difference between streamed entities and self-contained entities is less important for request entities created by the application and used only by HttpClient. In this case, it is recommended that non-repeatable reads are considered to be streamed entities, which can be read repeatedly as self-contained entities.

The Common httpentitystringentity
New Stringentity ("Important Message", Contenttype.create ("Text/plain", "UTF-8"));     New HttpPost ("http://www.example.com/"); httppost.setentity (entity);
Urlencodedformentity
New Arraylist<namevaluepair>(); Formparams.add (new basicnamevaluepair ("param1", "value1") ); Formparams.add (new basicnamevaluepair ("param2", "value2"new  Urlencodedformentity (Formparams, consts.utf_8);
Fileentity
File File = new file ("Hello.txt"); httpentity entity = new fileentity (file, Contenttype.create ("Text/plain", "UTF-8"));  
Bytearrayentity
New Bytearrayentity ("Important Message". GetBytes ());
Bytearrayinputstream
New Bytearrayinputstream ("Important Message". GetBytes ());
Serializableentity
New Serializableentity ("important message");

Entitybuilder

You can create httpentity instances from Entitybuilder, Entitybuilder has several setter methods for setting entity content, which are mutually exclusive, and if these methods are called more than once, only the last call will work.
SetText (String)
Setbinary (byte[])
SetStream (Java.io.InputStream)
Setserializable (java.io.Serializable)
Setparameters (java.util.list<namevaluepair>)
Setparameters (Org.apache.http.NameValuePair ...)
Setfile (Java.io.File)

Using Entitybuilder
httpentity entity = entitybuilder.create ()    . SetText ("Important Message")    . setContentType ( Contenttype.create ("Text/plain", "UTF-8"))    . Build ();

HttpClient (4.3.5)-HTTP Entity

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.