?JSONObject json = new JSONObject(); ???????????????????json.put("train_date", train_date); ???????????????????json.put("from_station", fromStationCode); ???????????????????json.put("to_station", toStationCode); ???????????????????json.put("logFlag", logFlag); ???????????????????HttpHeaders headers = new HttpHeaders(); ???????????????????MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8"); ???????????????????headers.setContentType(type); ???????????????????headers.add("Accept", MediaType.APPLICATION_JSON.toString()); ???????????????????HttpEntity<String> formEntity = new HttpEntity<String>(json.toString(), headers); ???????????????????String s= restTemplate.postForEntity(url,formEntity,String.class).getBody();
RestTemplate发送json请求
原文地址:https://www.cnblogs.com/yongguang1990/p/10223857.html