zoukankan      html  css  js  c++  java
  • RestTemplate的用法总结

    1.post

    (1)带header

      public static String postUrlWithHeader(RestTemplate restTemplate, String url, HeaderModel header, String json) throws Exception{
       HttpHeaders requestHeaders = new HttpHeaders();
             requestHeaders.setContentType("UTF-8");
             HttpEntity<String> requestEntity = new HttpEntity<String>(json, requestHeaders);
             
       ResponseEntity<String> res = restTemplate.postForEntity(url, requestEntity , String.class);
       String temp2 = null;
       if(res.getStatusCodeValue()== 200 && !StringUtils.isEmpty(res.getBody())){
        
        String xmlStr = res.getBody().toString();
         // 将xml转为json
         JSONObject xmlJSONObj = XML.toJSONObject(xmlStr);
         
         // 设置缩进
         String jsonPrettyPrintString = xmlJSONObj.toString(4);
        JSONObject temp = JSON.parseObject(jsonPrettyPrintString);
        //取key=ResultUtil的值
        temp2 = JsonProcess.returnValue(temp, "ResultUtil");
        
       }
       return temp2; 
      }

    (2)

    restTemplate相关连接:

    https://www.cnblogs.com/javazhiyin/p/9851775.html

  • 相关阅读:
    comet技术
    OCP-1Z0-052-V8.02-120题
    OCP-1Z0-052-V8.02-121题
    OCP-1Z0-052-V8.02-122题
    OCP-1Z0-052-V8.02-124题
    OCP-1Z0-052-V8.02-125题
    OCP-1Z0-052-V8.02-126题
    OCP-1Z0-052-V8.02-127题
    RMAN 备份脚本
    Oracle DB 性能视图和数据字典
  • 原文地址:https://www.cnblogs.com/pro-wall-box/p/12335602.html
Copyright © 2011-2022 走看看