zoukankan      html  css  js  c++  java
  • RestTemplate调用POST接口

    
    
    -----------------------------------------------------------------------------
    body内容:
    {
         "name":"mark",
        "orgIds": ["111","222"],
    }

    RestTemplate调用POST接口示例:
                    String url = "127.0.0.1:8080/resources?id=1";
                    JSONObject json = new JSONObject();
                    json.put("orgIds", Arrays.asList("1111","222"));
                    json.put("name", "mark");
                    HttpHeaders headers = new HttpHeaders();
                    headers.setContentType(org.springframework.http.MediaType.APPLICATION_JSON_UTF8);
                    headers.add("Accept", org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE);
                    MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
                    HttpEntity<JSONObject> entity = new HttpEntity<>(json, headers);
                    String result = new RestTemplate().postForObject(url, entity, String.class);
                    JSONObject JsonObject = JSONObject.parseObject(result);
                    JsonObject = JSON.parseObject(JsonObject.getString("content"));
  • 相关阅读:
    css
    bootstrap
    在线小工具
    文档工具-Markdown
    js
    棋盘问题(深搜,统计)
    ****Curling 2.0(深搜+回溯)
    POJ 2676 Sudoku(深搜)
    POJ 2488 A Knight's Journey(深搜+回溯)
    ural 1104. Don’t Ask Woman about Her Age
  • 原文地址:https://www.cnblogs.com/Alwaysbecoding/p/6720393.html
Copyright © 2011-2022 走看看