当前位置:   article > 正文

restTemplagte发送Post请求_resttemplate发送post

resttemplate发送post
  1. @GetMapping("/rest")
  2. public void rest(){
  3. HttpHeaders headers = new HttpHeaders();
  4. headers.setContentType(MediaType.APPLICATION_JSON);
  5. HashMap <Object,Object>map=new HashMap();
  6. map.put("name","dasdad");
  7. //用HttpEntity封装整个请求报文
  8. HttpEntity<HashMap<String, Object>> request = new HttpEntity(map, headers);
  9. String re= restTemplate.postForObject("http://localhost:8083/s",request,String.class);
  10. // String forObject = restTemplate.getForObject("http://localhost:8083/sys/test2", String.class);
  11. System.out.println("response:"+re);
  12. }
  13. @PostMapping("/s")
  14. public String test(@RequestBody String name){
  15. System.out.println(name);
  16. return "vvvv";
  17. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/303083
推荐阅读
相关标签
  

闽ICP备14008679号