HttpClient POST Request

Source: Internet
Author: User

This article uses httpcomponents-client-4.4.1 formerly known as HTTP client


When sending post data, the data is typically UrlEncode transcoded---urlencode or urlencodedformentity.

The following items are used to set the HTTP request header encoding or request content properties, specifically please Baidu.

//. AddHeader ("Accept-charset", "Utf-8")//fail

. AddHeader ("Content-type", "Text/plain;charset=utf-8")//fail

. AddHeader ("Content-type", "application/x-www-form-urlencoded")

Static void t3 () {Stringbuffer mobiles = new stringbuffer ()  .append (" 13581xxxxxx "). Append (", ")  .append (" 18669xxxxxx "). Append (", ")  .append (" 13121xxxxxx "). Append (", ")  .append ("18210xxxxxx"). Append (",")  .append ("15811xxxxxx"). Append (",")  .append ("15331xxxxxx"). Append (",")  .append ("18501xxxxxx"). Append (",")  .append ("13699xxxxxx"). Append (",")  .append (" 18500xxxxxx "). Append (", ")  .append (" 18310xxxxxx "). Append (", ")  .append (" 13581xxxxxx "); string msg =  "Hello staff, thank you for your cooperation in this test. "; List<namevaluepair> ls = new arraylist<> (); Ls.add (New BasicNameValuePair ( "UserId",  "jxxxx"), Ls.add (New basicnamevaluepair ("Password",  "5xxx3"); Ls.add (new  Basicnamevaluepair ("Mobis",  mobiles.tostring ())); Ls.add (New basicnamevaluepair ("msg",  msg)); Ls.add (New basicnamevaluepair ("Mobicount",  " + 11"); Ls.add (New basicnamevaluepair (" AubporT ", ")), Ls.add (New basicnamevaluepair ("MsgId",  "98xxxx31")); try {httpentity entity  = request.post ("Http://61.1xx.xxx.29:xxxx/Mxxx/wxxx.axxx/MxxxxxSubmit"). ConnectTimeout. Body ( New urlencodedformentity (LS, "UTF-8")). Execute (). Returnresponse (). GetEntity (); Entity.writeto (System.out);}  catch  (exception e)  {e.printstacktrace ();}}



HttpClient POST Request

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.