今儿同事调接口时,发现对方返回的HttpResponse是经GZIP加密的,调用一个现成的解压Util总是失败。经查阅资料,个人封装了一个自带解压功能的post方法,适用于返回结果经GZIP加密的post请求,Get请求请自行更改。废话少说,上代码。
private String postGZIP(String url, String requestJson, String authorization)throws Exception {
HttpClient httpClient = HttpClients.createDefault();
HttpPost httppost =null;
String postUrl =null;
HttpResponse response =null;
String json =null;
try{
postUrl = url +"?param="+ requestJson;
httppost =new HttpPost(postUrl);
List<NameValuePair> params =new ArrayList<NameValuePair>();
params.add(new BasicNameValu