• 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"));
  • 相关阅读:
    c++11:智能指针
    C++11:右值引用
    结构体与联合体
    数组与指针的区别?
    堆和栈的理论知识
    笔试点杂烩
    2、8、10、16进制输出
    单链表的反转
    签约新国都
    Linux下使用autoconf 和 automake 编译简单的HelloWorld
  • 原文地址:https://www.cnblogs.com/Alwaysbecoding/p/6720393.html
Copyright © 2020-2023  润新知