HTTP中POS请求方法

private static final RestTemplate restTemplate = new RestTemplate();

public static String POST(String url, Object params) {

HttpHeaders headers = new HttpHeaders();
System.out.println(JSONObject.toJSON(params));
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
HttpEntity request = new HttpEntity<>(JSONObject.toJSON(params).toString(), headers);
ResponseEntity entity = restTemplate.postForEntity(url, request, String.class);
System.out.println(entity);
return entity.toString();
}

你可能感兴趣的:(java代码)