Using the Java impersonation Client for submission requires the Apache HTTP client jar, which is used in version 4.4
GET:
public void GetURL () {
String strresp= "";
String url= "www.baidu.com";
int statuscode=0;
Closeablehttpclient Client=httpclients.createdefault ();
HttpGet request=new httpget (URL);
try{
HttpResponse Response=client.execute (Request);
Statuscode=response.getstatusline (). Getstatuscode ();
if (statuscode==200) {
Strresp=entityutils.tostring (Response.getentity ());//content returned
}
}catch (Exception e) {
E.printstacktrace ();
}
POST:
Public String PostURL () {
String strresp= "";
String url= "www.baidu.com";
int statuscode=0;
Closeablehttpclient client = Httpclients.createdefault ();
HttpPost request=new httppost (URL);
Jsonstringer Jsonbody;
try{
Jsonbody= (Jsonstringer) New Jsonstringer (). Object (). Key ("Vehicleid"). Value ("8856017585"). EndObject ();
Stringentity se=new stringentity (jsonbody.tostring (), "UTF-8");
Se.setcontenttype ("Application/json");
Request.setentity (SE); Set the content to post, currently using JSON format
HttpResponse Response=client.execute (Request);
Statuscode=response.getstatusline (). Getstatuscode ();
if (STATUSCODE==HTTPSTATUS.SC_OK) {
Strresp=new String (entityutils.tostring (Response.getentity ()). GetBytes ("UTF-8")); }
Client.close ();
}catch (Exception e) {
E.printstacktrace (); }
return STRRESP; }
Java analog httpclient for Get and post submissions