RestTemplate发送json请求

时间:2019-01-05 13:06:13   收藏:0   阅读:530
  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();

 

原文:https://www.cnblogs.com/yongguang1990/p/10223857.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!