Creates a default HttpClient instance.
Closeablehttpclient httpclient = Httpclients.createdefault ();
Create HttpPost
HttpPost HttpPost =//new httppost ("http://crmetl.yishenghuo.com:8142/outserver/startUpByHand.htm");
New HttpPost ("http://localhost:8087/outserver/startUpByHand.htm");
To create a parameter queue
list<namevaluepair> formparams = new arraylist<namevaluepair> ();
Formparams.add (New Basicnamevaluepair ("UserName", "admin"));
Formparams.add (New Basicnamevaluepair ("PassWord", "123456"));
Urlencodedformentity uefentity;
try {
uefentity = new Urlencodedformentity ((list<? extends org.apache.http.namevaluepair>) formparams, "UTF-8");
Httppost.setentity (uefentity);
Closeablehttpresponse HttpResponse = Httpclient.execute (HttpPost);
try {
httpentity entity = httpresponse.getentity ();
if (Entity! = null) {
0: Update succeeded, 1: Update failed, 2: Update, 3: Less than 1 hours from last update
Jsonobject json = new Jsonobject ();
if ("0". Equals (Entity)) {
Json.put ("code", "0");
Json.put ("Message", "Update succeeded!") ");
}else if ("1". Equals (Entity)) {
Json.put ("Code", "1");
Json.put ("message", entity+ "update failed! ");
}else if ("2". Equals (Entity)) {
Json.put ("Code", "2");
Json.put ("message", entity+ "in the update!) ");
}else if ("3". Equals (Entity)) {
Json.put ("Code", "3");
Json.put ("message", entity+ "is less than 1 hours from the last update, please update it later.) ");
}
Json.put ("message", "Unknown error ... ");
Response.getwriter (). Print (json.tojsonstring ());
Logger.info ("Updated Results:" +entityutils.tostring (Entity, "UTF-8"));
}
} finally {
Httpresponse.close ();
}
} catch (Clientprotocolexception e) {
E.printstacktrace ();
} catch (Unsupportedencodingexception E1) {
E1.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
} finally {
Close the connection and release the resource
try {
Httpclient.close ();
} catch (IOException e) {
E.printstacktrace ();
}
}
HttpClient Impersonation Server Request