使用hutool工具发送post请求

 import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
 
 
 
  JSONObject jsonObject = JSONUtil.createObj();
            jsonObject.put(“shift”, “D”);
            jsonObject.put(“model”, dataMap.get(“MODEL”));
            jsonObject.put(“stage”, dataMap.get(“STAGE_GROUP”));
            jsonObject.put(“reflow”, “Y”);
            jsonObject.put(“startTime”, startTime);
 
  private List<Map<String, String>> exchange(JSONObject jsonObject, Map<String, String> requestMap) {
 HttpResponse execute = HttpRequest.post(url)
                //设置请求头(可任意加)
                .header(“NginxModel”, requestMap.get(“MODEL”))
                .header(“NginxStage”, requestMap.get(“STAGE_GROUP”))
                .header(“NginxProcess”, requestMap.get(“FATP”))
                .header(“sign”, “e74167063074b180b6dafa567b2095a8f7996327”)
                //请求参数
                .body(jsonObject.toString())
                .execute();
        String body1 = execute.body();
        com.alibaba.fastjson2.JSONObject jsonObject1 = com.alibaba.fastjson2.JSONObject.parseObject(body1);
        List<Map<String, String>> dataList = (List<Map<String, String>>)jsonObject1.get(“data”);
        }

get请求 :HttpResponse response = HttpRequest.get(“http://127.0.0.1:9001/caiyun-record/login?paramData=I0CZZJYUBP9JixsyeDkhRnIfFgyXP-NaP1DiJ8_AWoY1eEeZN5BwF_HMSfb4wl6oE”)
                .execute();
        log.info(“get请求返回:{}”,response.body());
 

版权声明:本文为博主作者:shuaishuaiwang14987原创文章,版权归属原作者,如果侵权,请联系我们删除!

原文链接:https://blog.csdn.net/m0_64979027/article/details/130642469

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
扎眼的阳光的头像扎眼的阳光普通用户
上一篇 2024年1月3日
下一篇 2024年1月3日

相关推荐