Post请求回调接口

该代码段展示了如何使用HttpClient发送POST请求,设置请求头、参数,并处理响应。当响应状态为200时,读取并返回数据;否则记录错误信息。此外,还涉及到将List转换为Map中的值,以及对返回结果的进一步处理,如调用submit方法。
摘要由CSDN通过智能技术生成
   public static String postHttp(String url, String map) throws IOException {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);
        log.info("请求时间" + DateUtil.now() + "_请求URL" + url + "_请求参数" + map);
        // 设置请求的header
        httppost.addHeader("Content-type", "application/json");
        // 设置请求的参数
        StringEntity entity = new StringEntity(map, "utf-8");
        httppost.setEntity(entity);
        HttpResponse response = httpclient.execute(httppost);
        if (response.getStatusLine().getStatusCode() == 200) {
            /*读返回数据*/
            String conResult = EntityUtils.toString(response.getEntity());
            if (conResult != null && !conResult.equals("[]") && StringUtils.isNotBlank(conResult) && StringUtils.isNotBlank(conResult)) {
                log.info("请求时间" + DateUtil.now() + "_回调参数" + conResult);
                return conResult;
            } else {
                log.info("请求时间" + DateUtil.now() + "_返回数据为空");
                return "返回数据为空";
            }
        } else {
            String err = response.getStatusLine().getStatusCode() + "";
            log.error("请求时间" + DateUtil.now() + "_错误参数" + err);
            return err;
        }
    }

请求封装参数

 List<> redisData = getRedisData();
        for (HouseProperty redisDatum : redisData) {
            HousePropertyArrayList.add(redisDatum);
        } 

Map<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("systemId", "");
        stringObjectHashMap.put("isFull", "");

        // map键可以封装list作为值
        stringObjectHashMap.put("masterData", HousePropertyArrayList);
        String url;
        if (mdmHouseInfoEntities.size() == 1) {
            url = "";
        } else {
            url = ";
        }
        String s = postHttp(url, JSON.toJSONString(stringObjectHashMap));
        Map mapTypes = JSON.parseObject(s);
        if ("OK".equals(mapTypes.get("status"))){
            String fb = redisService.getFuzzyMatching("fs_house_u_*");
            sumit(fb);
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值