@RequestMapping(value = "/hivesd", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public ResponseEntity getHiveSampleData(@RequestBody GetHiveRequest getHiveRequest) { // --------------------------Post Json------------------------------- String hiveTableName = tableMappingService.findHiveTableNameByUserTableName(getHiveRequest); RestTemplate restTemplate = new RestTemplate(); //Http 请求URL String url = "http://localhost:8080/test"; //Http Header HttpHeaders headers = new HttpHeaders(); // 指定请求中的媒体类型信息 MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8"); headers.setContentType(type); //Accept代表发送端(客户端)希望接受的数据类型。 headers.add("Accept", MediaType.APPLICATION_JSON.toString()); String json = "{\"k1\":\"v1\"}"; HttpEntity<String> entity = new HttpEntity<String>(json, headers); String restResult = restTemplate.postForObject(url, entity, String.class); System.out.println(restResult); //-------------------------Post Form------------------------ url = "http://localhost:8080/testnotjson"; headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String, String> map= new LinkedMultiValueMap<String, String>(); map.add("key", "first.last@example.com"); map.add("key", "first.last@example.com111"); headers.add("Accept", MediaType.APPLICATION_JSON.toString()); HttpEntity<MultiValueMap<String, String>> request = new HttpEntity(map, headers); restResult = restTemplate.postForObject(url, request, String.class); System.out.println(restResult); return null; }