现在,我们准备发送POST请求。我们会调用RestTemplate的postForObject()方法来发送数据。以下是一个完整的例子: importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.web.bind.annotation.PostMapping;importorg.springframework.web.bind.annotation.RestController;importorg.springframework.web....
private static String post(String url, JSONObject params, MediaType mediaType) { RestTemplate restTemplate = new RestTemplate(); //拿到header信息 HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setContentType(mediaType); HttpEntity<JSONObject> requestEntity = (mediaType == MediaType....
public static JSONObject sendPostRequest(String url, Map params) { RestTemplate client =new RestTemplate(); return client.postForEntity(url, params, JSONObject.class).getBody(); }