httpClient的xml,form,json提交

http可以实现多种提交(同理restamplate也一样)

提供url 和 参数由httpclient模拟相应的提交

 1,提交xml数据

 2,提交form表单的数据

 3,提交普通的json数据

1,

@Override

    public ApiResponse send(FacadeSendRequest facadeSendRequest) throws Exception{

Assert.isTrue(!StringUtil.isBlank(facadeSendRequest.getTradeCode()), "转发地址异常!");

//根据交易编码获得三湘的接口调用方法名

urlEnum = UrlTransEnum.getEnumByCode(facadeSendRequest.getBankCode(),facadeSendRequest.getTradeCode());

if(urlEnum == null){

log.error("渠道:[{}]不支持此业务,请检查!交易码:[{}]",facadeSendRequest.getBankCode(),facadeSendRequest.getTradeCode());

throw new ParamException(CodeEnum.CODE_0027.getMsg()+"{"+facadeSendRequest.getTradeCode()+"}");

}

if (TradeEnum.S0017.getTcode().equals(facadeSendRequest.getTradeCode())

|| TradeEnum.S0018.getTcode().equals(facadeSendRequest.getTradeCode())

|| TradeEnum.S0019.getTcode().equals(facadeSendRequest.getTradeCode())

|| TradeEnum.S0020.getTcode().equals(facadeSendRequest.getTradeCode())

|| TradeEnum.S0021.getTcode().equals(facadeSendRequest.getTradeCode())

|| TradeEnum.S0022.getTcode().equals(facadeSendRequest.getTradeCode())

|| TradeEnum.S0023.getTcode().equals(facadeSendRequest.getTradeCode())) {//http form post send

JSONObject packetJson = JSONObject.parseObject(facadeSendRequest.getPacket());

facadeSendRequest.setFormData(packetJson);

return super.send(facadeSendRequest);

}else{//api send

return apiSend(facadeSendRequest);

}

    }

2,

public String httpSend(FacadeSendRequest facadeSendRequest){

    if(facadeSendRequest.getFile() != null)

    return HttpClientUtil.uploadFile(facadeSendRequest.getUrl(), facadeSendRequest.getFileKey(),facadeSendRequest.getFile(),facadeSendRequest.getDatas());

    if(!StringUtil.isBlank(facadeSendRequest.getXmlPacket()))

    return HttpClientUtil.httpXmlPost(facadeSendRequest.getUrl(), facadeSendRequest.getXmlPacket(), facadeSendRequest.getEncoding());

        if(!CollectionUtils.isEmpty(facadeSendRequest.getFormData()))

            return HttpClientUtil.httpFormPost(facadeSendRequest.getUrl(), facadeSendRequest.getFormData());

    return HttpClientUtil.httpJsonPost(facadeSendRequest.getUrl(), facadeSendRequest.getPacket());

    }

工具类看附件