private static RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(60000).setConnectTimeout(60000).setConnectionRequestTimeout(60000).build();

try
{ CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost("http://xxxxxxxxx:xxxx/xxxx"); httpPost.addHeader("Content-Type", "application/json");// 这里请求方式设置为json,按需要修改 String body = "{\"xxxxx\":xxxx}"; httpPost.setEntity(new StringEntity(body, "UTF-8"));// 为了防止传过去的中文乱码,这里设置字符编码 CloseableHttpResponse response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity(); String responseContent = EntityUtils.toString(entity, "UTF-8"); // 处理请求结果 Map<String, Object> resultMap = JSON.parseObject(responseContent); response.close(); httpClient.close(); } catch (Exception e) { System.out.println(e.getMessage()); }

 

posted on 2018-09-29 16:30  沛昕的博客  阅读(569)  评论(0编辑  收藏  举报