栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

用post方式发送请求报文

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

用post方式发送请求报文

post请求:

//获取请求地址
        String url = CbsConfig.getCfg("QUERYHOLDERBANKINFODETAIL");
        HolderBankInfoDetailDTO reultInfo;
        Map request = new HashMap<>();
        request.put("policy_uuid",policyUuid);
        HttpPost httpPost = null;
        HttpResponse respost = null;
        HolderBankInfoDetailResponseDTO response = new HolderBankInfoDetailResponseDTO();
        httpPost = new HttpPost(url);
        httpPost.setHeader("Content-Type", "application/json;charset=utf8");
        httpPost.setHeader("organ_id", map.get("organ_id"));
        String requestJson = JsonUtils.obj2Json(request);
        logger.info("保单号:{},请求报文:{},请求路径:{}", policyUuid,requestJson, url);
        StringEntity se = new StringEntity(requestJson, "utf-8");
        httpPost.setEntity(se); //post方法中,加入json数据
        RequestConfig requestConfig =  RequestConfig.custom().setSocketTimeout(120000).setConnectTimeout(120000).build();
        httpPost.setConfig(requestConfig);


        HttpClient httpClient = HttpClientBuilder.create().build();
        try {
            respost = httpClient.execute(httpPost);
            // 从响应模型中获取响应实体
            String jsResponse = EntityUtils.toString(respost.getEntity(), "UTF-8").trim();
            logger.info("保单号:{},返回报文:{}", policyUuid, JSON.toJSonString(jsResponse));
            if (StringUtils.isNotBlank(jsResponse)) {
                response = JsonUtils.json2Obj(jsResponse, HolderBankInfoDetailResponseDTO.class);
            }
        } catch (IOException e) {
            logger.error("返回异常:{},保单号:{}", ExceptionUtils.getStackTrace(e), policyUuid);
            return null;
        }

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/269167.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号