HttpClient Use Example

Source: Internet
Author: User

HttpClient client =NewHttpClient (); String URL= http://Localhost:8080/ana/workflowoainterface.do?action=oatask;Postmethod Postmethod =Newpostmethod (URL);//Set parameter encoding to GBKPost.getparams (). Setparameter (Httpmethodparams.http_content_charset, "GBK");//constructing key-value pair parametersnamevaluepair[] data = {NewNamevaluepair ("Processinstanceid", "230"),NewNamevaluepair ("Approveflag", "1") }; //put the parameter values into the Postmethodpostmethod.setrequestbody (data);//Execution
Client.executemethod (Postmethod);//Get Execution Result code
//Read Content    byte[] Responsebody =Postmethod.getresponsebody (); //Working with ContentSystem.out.println (NewString (responsebody)); System.out.println ("Getstatusline:" +postmethod.getstatusline ()); System.out.println ("~~~"+postmethod.getresponsebodyasstring ()); System.out.println ("StatusCode:" +StatusCode); //Print results pageString response =NewString (Postmethod.getresponsebodyasstring (). GetBytes ("Utf-8")); //Print the returned informationSYSTEM.OUT.PRINTLN ("Response:" +response);//Release ConnectionPostmethod.releaseconnection ();
If the Chinese parameter is passed, it is possible to get garbled and resolve it by setting the correct parameter encoding. In the called interface side, directly through the request.getparameter way to obtain. Original: http://blog.sina.com.cn/s/blog_49cc672f0100x7sh.html

HttpClient Use Example

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.