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)