CloseableHttpClient httpClient = HttpClients.createDefault();
//如果发送是POST请求,创建HttpPost对象
HttpPost httppost = new HttpPost("http://localhost:8080/login");
//post请求参数配置
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("name", "xxx"));
formparams.add(new BasicNameValuePair("pwd", "123456"));
UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8"); //设置编码格式为utf-8
httppost.setEntity(uefEntity); //设置POST请求参数
//使用httpclient的execute方法发送接口请求
CloseableHttpResponse response = httpClient.execute(httppost);