RestTemplate傳送json請求
阿新 • • 發佈:2019-01-05
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 = newHttpEntity<String>(json.toString(), headers); String s= restTemplate.postForEntity(url,formEntity,String.class).getBody();