restTemplate.postForObject接口请求

一、post请求【接口请求参数有params】

       RestTemplate restTemplate = new RestTemplate();
        String url =domesticAPP_url_Online+"readBook/listReadBookByCode";

    
        JSONObject paramsJ = JSON.parseObject(params);
        Map map = new HashMap();
        map.put("token",LoginToken);

        MultiValueMap<String, Object> postParameters =  new LinkedMultiValueMap();
        postParameters.add("params", JSON.toJSONString(map));    //http接口请求类型为json格式

        /*调用接口*/
        HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(postParameters,headers);
        JSONObject response = restTemplate.postForObject(url, request, JSONObject.class);

  

原文地址:https://www.cnblogs.com/jiangger/p/14894656.html