| | |
| | | |
| | | |
| | | HttpPost post = new HttpPost(url); |
| | | post.setHeader("Accept", "application/json"); |
| | | post.setHeader("Accept-Encoding", "gzip"); |
| | | // post.setHeader("Cache-Control", "no-cache"); |
| | | // post.setHeader("Connection", "keep-alive"); |
| | | post.setHeader("Content-Type", "application/json;charset=UTF-8"); |
| | | |
| | | List<NameValuePair> paramaters = new ArrayList<>(); |
| | | |
| | |
| | | String token, |
| | | Map<String, Object> map) { |
| | | // 返回body |
| | | String body = null; |
| | | String res = null; |
| | | // 获取连接客户端工具 |
| | | CloseableHttpClient httpClient = HttpClients.createDefault(); |
| | | CloseableHttpResponse httpResponse = null; |
| | |
| | | // 5、设置header信息 |
| | | /**header中通用属性*/ |
| | | post.setHeader("Accept", "application/json"); |
| | | post.setHeader("Accept-Encoding", ""); |
| | | // post.setHeader("Cache-Control", "no-cache"); |
| | | // post.setHeader("Connection", "keep-alive"); |
| | | post.setHeader("Accept-Encoding", "gzip"); |
| | | post.setHeader("Content-Type", "application/json;charset=UTF-8"); |
| | | /**业务参数*/ |
| | | post.setHeader("appId",appId); |
| | | post.setHeader("timestamp",timestamp); |
| | | post.setHeader("transId",transId); |
| | | post.setHeader("token",token); |
| | | // 设置参数 |
| | | HashMap<Object, Object> hashMap = new HashMap<>(4); |
| | | hashMap.put("appId",appId); |
| | | hashMap.put("timestamp",timestamp); |
| | | hashMap.put("transId",transId); |
| | | hashMap.put("token",token); |
| | | String head = hashMap.toString(); |
| | | post.setHeader("head",JSON.toJSONString(head)); |
| | | String body = JSON.toJSONString(map); |
| | | |
| | | // 设置参数 |
| | | if (map != null) { |
| | | try { |
| | | StringEntity entity1 = new StringEntity(JSON.toJSONString(map), "UTF-8"); |
| | | StringEntity entity1 = new StringEntity(body, "UTF-8"); |
| | | entity1.setContentEncoding("UTF-8"); |
| | | entity1.setContentType("json/form-data"); |
| | | post.setEntity(entity1); |
| | |
| | | HttpEntity entity = httpResponse.getEntity(); |
| | | if (entity != null) { |
| | | // 按指定编码转换结果实体为String类型 |
| | | body = EntityUtils.toString(entity, "UTF-8"); |
| | | res = EntityUtils.toString(entity, "UTF-8"); |
| | | } |
| | | try { |
| | | httpResponse.close(); |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return body; |
| | | return res; |
| | | } |
| | | |
| | | public static SSLContext createIgnoreVerifySSL() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException { |
| | |
| | | //创建自定义的httpclient对象 |
| | | CloseableHttpClient client = HttpClients.custom().setConnectionManager(connManager).build(); |
| | | HttpPost post = new HttpPost(url); |
| | | post.setHeader(appKey, appKeyValue); |
| | | // post.setHeader(appKey, appKeyValue); |
| | | CloseableHttpResponse res = null; |
| | | try { |
| | | List<NameValuePair> nvps = new ArrayList<NameValuePair>(); |