码迷,mamicode.com
首页 > Web开发 > 详细

RestTemplate发送json请求

时间:2019-01-05 13:29:54      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:utf-8   parse   url   dia   post   nbsp   form   lag   ade   

  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请求

标签:utf-8   parse   url   dia   post   nbsp   form   lag   ade   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!