HttpHeader,restTemplate.postForObject()使用

HttpHeader,restTemplate.postForObject()使用
 
         
1
import org.springframework.web.client.RestTemplate;
2
3
    @Autowired
4
    private RestTemplate restTemplate;
5
6
    @RequestMapping(value = "/sync.php", method = {RequestMethod.GET, RequestMethod.POST})
7
    @ResponseBody
8
    public String sync(HttpServletRequest request, @RequestBody(required = false) String body) throws IOException {
9
        HttpHeaders headers = new HttpHeaders();
10
        headers.setContentType(MediaType.APPLICATION_JSON);
11
        HttpEntity<String> entity = new HttpEntity<>(body, headers);
12
        if ("rent_confirm".equals(submit)) {
13
            logger.info("======rent_confirm param======:" + request.getParameter("sid"));
14
            logger.info("======rent_confirm entity======:" + entity);
15
            result = restTemplate.postForObject("http://socket:18084/rent_confirm/rent_confirm?sid=" + request.getParameter("sid"), entity, String.class);
16
        }
17
    }   
18
      

你可能感兴趣的:(http)