1、可以通过CloseableHttpClient httpclient = HttpClients.createDefault();创建一个连接对象
2、然后 通过HttpPost httppost=new HttpPost("http://localhost:8080/sanliudu/swing/swingFindImage");去建立要连接的服务器地址;
3、创建一个 消息队列,用来传输参数
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("userid", "3"));//要传递的参数 参数名为userid 参数值为3
4、UrlEncodedFormEntity uefEntity=new UrlEncodedFormEntity(formparams, "UTF-8");不太理解这和是干嘛的 猜想应该是为参数设置一定的编码格式
5、调用httppost.setEntity(uefEntity);将参数放进请求中
6、调用response=httpclient.execute(httppost);执行请求,该请求会返回一个response对象
7、使用response 对象调用HttpEntity entity =response.getEntity();返回一个HttpEntity d对象,该对象存有服务器响应后返回的数据;
8、输出 EntityUtils.toString(entity)及可打印该对象存放的值。
简单的HttpClients请求服务器就完事了