HttpClientUtil有两个常用的方法
String result = httpClientUtil.sendPostUrl(url, map, "UTF-8");
String result = httpClientUtil.sendPost(url, map, "UTF-8");
两个方法传递参数的方式不同,所以获取参数的方式也不同
sendPostUrl获取参数:
String method = request.getParameter("method");
sendPost获取参数:
Map<String, Object> params = new HashMap<>();
// 获取内容格式
String contentType = request.getContentType();
if ("application/json; charset=UTF-8".equalsIgnoreCase(contentType)) {
// 使用 commons-io中 IOUtils 类快速获取输入流内容
String paramJson = IOUtils.toString(request.getInputStream(), "UTF-8");
Map parseObject = JSON.parseObject(paramJson, Map.class);
params.putAll(parseObject);
}