码迷,mamicode.com
首页 > 其他好文 > 详细

restTemplate

时间:2019-12-01 20:44:24      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:out   接收   exchange   content   方式   epo   cat   array   converter   

    http://localhost:9093/myTestHttp?name=1 访问
    @ResponseBody
    public TestReponse myTestHttp(TestRequest request){// name为属性值


@Autowired
@Qualifier("restTemplate")
private RestTemplate rest;

访问者 HttpHeaders hh = new HttpHeaders(); hh.setContentType(new MediaType("application","json", Charset.forName("UTF-8"))); hh.setAccept(Arrays.asList(new MediaType("application","json", Charset.forName("UTF-8")))); // hh.setContentType(MediaType.APPLICATION_JSON_UTF8); JSONObject s = new JSONObject(); s.put("name","wsd"); s.put("age","sd"); //String json = "{‘name‘:‘s‘}"; System.out.println("request:"+s.toString()); HttpEntity<String> he = new HttpEntity<String>(s.toString(),hh); ResponseEntity<String> ex = rest.exchange("http://localhost:9093/myTestHttp", HttpMethod.POST,he,String.class); // ResponseEntity<String> ex = rest.postForEntity("http://localhost:9093/myTestHttp",he,String.class); String res = ex.getBody(); System.out.println(" res: "+res); 提供者 public TestReponse myTestHttp(TestRequest request){// name为属性值 结果: 访问者用json方式请求name值无法传递 public TestReponse myTestHttp(String name,String age){ //提供者如此修改,可接收name 必须有 MappingJackson2HttpMessageConverter @@@待解决 public TestReponse myTestHttp(@RequestBody Map<String,String> request){ //提供者如此修改,可接收name

  

restTemplate

标签:out   接收   exchange   content   方式   epo   cat   array   converter   

原文地址:https://www.cnblogs.com/xingminghui/p/11967251.html

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