| | |
| | | package com.iailab.module.data.common.utils; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.http.Header; |
| | | import org.apache.http.HttpEntity; |
| | |
| | | * doPost |
| | | * |
| | | * @param url |
| | | * @param jsonStr |
| | | * @param date |
| | | * @param charset |
| | | * @return |
| | | */ |
| | | public String doPost(String url, String jsonStr, String date, String charset) { |
| | | org.apache.http.client.HttpClient httpClient = null; |
| | | HttpPost httpPost = null; |
| | | String result = null; |
| | | try { |
| | | httpClient = new SSLClient(); |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append(url); |
| | | sb.append("/"); |
| | | sb.append(date); |
| | | log.info("url=====" + sb.toString()); |
| | | httpPost = new HttpPost(sb.toString()); |
| | | //设置参数 |
| | | httpPost.addHeader("Content-Type", "application/json;charset=UTF-8"); |
| | | StringEntity stringEntity = new StringEntity(jsonStr); |
| | | stringEntity.setContentEncoding("UTF-8"); |
| | | stringEntity.setContentType("application/json"); |
| | | httpPost.setEntity(stringEntity); |
| | | HttpResponse response = httpClient.execute(httpPost); |
| | | if (response != null) { |
| | | HttpEntity resEntity = response.getEntity(); |
| | | if (resEntity != null) { |
| | | result = EntityUtils.toString(resEntity, charset); |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | // ex.printStackTrace(); |
| | | log.info("doPost失败,url=" + url); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * doPost |
| | | * |
| | | * @param url |
| | | * @param map |
| | | * @param json |
| | | * @param charset |
| | | * @param token |
| | | * @return |
| | | */ |
| | | public String doPost(String url, Map<String, String> map, String json, String charset, String token) { |
| | | public String doPostForToken(String url, Map<String, String> map, String json, String charset, String token) { |
| | | org.apache.http.client.HttpClient httpClient = null; |
| | | HttpPost httpPost = null; |
| | | String result = null; |