String httpRes="";//get the results
CloseableHttpClient httpClient=null;
CloseableHttpResponse response=null;
The String url="http://xx.x.x:x/aa";
String MSG=""
Try {
HttpClient=HttpClients. CreateDefault ();
HttpPost post=new HttpPost (url);
RequestConfig RequestConfig=RequestConfig. Custom (.) setSocketTimeout (6000). SetConnectTimeout (3000). The build ();
Post. SetConfig (requestConfig);
String Body=URLEncoder. Encode (MSG, "utf-8");
//build content
List
FormParams. Add (new BasicNameValuePair (" Body ", the Body));
HttpEntity entity=new UrlEncodedFormEntity (formParams, "utf-8");
//send data request
Post. AddHeader (" the content-type ", "application/x - WWW - form - urlencoded; charset=UTF-8");
Post. SetEntity (entity);
Try {
The response=httpClient. Execute (post);
//removed from the response object HttpEntity
HttpEntity entity1=response. GetEntity ();
HttpRes=EntityUtils. ToString (entity1, "utf-8");
EntityUtils. Consume (response. GetEntity ());//completely consumption
} the catch (IOException e) {
e.printStackTrace();
} the finally {
Try {
if (null !=response)
The response. The close ();
} the catch (IOException e) {
e.printStackTrace();
}
}
} the catch (Exception e) {
e.printStackTrace();
} the finally {
//release link
Try {
HttpClient. Close ();
} the catch (Exception e) {
e.printStackTrace();
}
}
Return httpRes;