zoukankan      html  css  js  c++  java
  • spring里restTemplate向目的URL发送post请求

    /**
    * 向目的URL发送post请求
    * @param url 目的url
    * @param userDTO 发送的参数
    * @return ResultVO
    */
    public static User sendPostRequest(String url, UserDTO userDTO, String authorization ){
    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", authorization);
    headers.add("FROM_IN", SecurityConstants.FROM_IN);

    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<String> entity = new HttpEntity(JSONUtil.parseObj(userDTO), headers);
    ResponseEntity<JSONObject> response = restTemplate.postForEntity(url, entity, JSONObject.class);
    Object data = response.getBody().get("data");

    ConverterRegistry converterRegistry = ConverterRegistry.getInstance();
    User userInfo = converterRegistry.convert(User.class, data);

    return userInfo;
    }
  • 相关阅读:
    CentOS8 安装 Java JDK
    小程序问题汇总
    CSS实现侧边栏固定宽度,内容栏自适应
    垂直居中总结
    移动端Web App自适应布局探索
    学习指南
    插件集
    移动端滑动事件
    网站收藏
    js void运用
  • 原文地址:https://www.cnblogs.com/hmpcly/p/10250524.html
Copyright © 2011-2022 走看看