HttpClient request data (POST)

Source: Internet
Author: User

 Public Staticstring Logincheck_post_httpclient (string name,string pass,string URL) {string result=""; HttpPost Post=NewHttpPost (URL);//Create a POST request object for HttpClient//Set Request ParametersHttpparamsparams=NewBasichttpparams (); Httpconnectionparams.setconnectiontimeout (params,5* +); Httpconnectionparams.setsotimeout (params,5* +); //Pass Value//Create a list collection that holds the data passed to the serverList<namevaluepair> Reqdata =NewArraylist<namevaluepair>(); Namevaluepair P1=NewBasicnamevaluepair ("username", name); Namevaluepair P2=NewBasicnamevaluepair ("Userpass", pass);        Reqdata.add (p1);                Reqdata.add (p2); Try{httpentity entity=NewUrlencodedformentity (Reqdata,"Utf-8"); Post.setentity (entity);//set the uploaded data to the Post request objectHttpClient client =NewDefaulthttpclient (params);//Create a HttpClient objectHttpResponse res = Client.execute (POST);//perform a POST request to get results            if(Res.getstatusline (). Getstatuscode () = = $) {httpentity resentity= Res.getentity ();//to obtain the corresponding result, is a Httpentity objectresult = Entityutils.tostring (resentity,"Utf-8");//Convert to String            }        } Catch(unsupportedencodingexception E1) {//TODO auto-generated Catch blockE1.printstacktrace (); } Catch(clientprotocolexception e) {//TODO auto-generated Catch blockE.printstacktrace (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); }                returnresult; }    

HttpClient request data (POST)

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.