| @@ -4,7 +4,6 @@ import okhttp3.MediaType; | |||
| import okhttp3.OkHttpClient; | |||
| import okhttp3.Request; | |||
| import okhttp3.RequestBody; | |||
| import org.apache.commons.codec.Charsets; | |||
| import org.apache.commons.io.IOUtils; | |||
| import org.apache.http.*; | |||
| import org.apache.http.client.entity.UrlEncodedFormEntity; | |||
| @@ -19,6 +18,8 @@ import org.apache.http.message.BasicNameValuePair; | |||
| import org.apache.http.protocol.HTTP; | |||
| import org.apache.http.ssl.SSLContexts; | |||
| import org.apache.http.util.EntityUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import javax.net.ssl.HttpsURLConnection; | |||
| import javax.net.ssl.KeyManager; | |||
| @@ -34,7 +35,6 @@ import java.util.ArrayList; | |||
| import java.util.Iterator; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.logging.Logger; | |||
| /** | |||
| @@ -44,7 +44,7 @@ import java.util.logging.Logger; | |||
| */ | |||
| public class HttpUtil { | |||
| private static Logger logger = Logger.getLogger(String.valueOf(HttpUtil.class)); | |||
| private static final Logger logger = LoggerFactory.getLogger(ETCPUtil.class); | |||
| private static final MediaType CONTENT_TYPE_FORM = MediaType.parse("application/x-www-form-urlencoded"); | |||
| private static final String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36"; | |||
| @@ -70,7 +70,8 @@ public class HttpUtil { | |||
| } | |||
| } | |||
| catch (IOException e) { | |||
| e.printStackTrace(); | |||
| logger.error(e.getMessage()); | |||
| throw new RuntimeException(e); | |||
| } | |||
| return null; | |||
| @@ -124,13 +125,12 @@ public class HttpUtil { | |||
| return sb.toString(); | |||
| } | |||
| else{ // | |||
| System.out.println("状态码:" + code); | |||
| logger.info("状态码:" + code); | |||
| client.close(); | |||
| } | |||
| } | |||
| catch(Exception e){ | |||
| e.printStackTrace(); | |||
| logger.error(e.getMessage()); | |||
| return null; | |||
| } | |||
| @@ -172,13 +172,13 @@ public class HttpUtil { | |||
| try { | |||
| response.close(); | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| logger.error(e.getMessage()); | |||
| } | |||
| } | |||
| try { | |||
| httpclient.close(); | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| logger.error(e.getMessage()); | |||
| } | |||
| } | |||
| return null; | |||
| @@ -196,6 +196,7 @@ public class HttpUtil { | |||
| .url(url).post(body).build(); | |||
| return exec(request); | |||
| } catch (IOException e) { | |||
| logger.error(e.getMessage()); | |||
| return null; | |||
| } | |||
| } | |||
| @@ -207,6 +208,7 @@ public class HttpUtil { | |||
| throw new RuntimeException("Unexpected code " + response); | |||
| return response.body().string(); | |||
| } catch (IOException e) { | |||
| logger.error(e.getMessage()); | |||
| throw new RuntimeException(e); | |||
| } | |||
| } | |||
| @@ -252,6 +254,7 @@ public class HttpUtil { | |||
| } | |||
| return sb.toString(); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| throw new RuntimeException(e); | |||
| } finally { | |||
| IOUtils.closeQuietly(out); | |||
| @@ -289,17 +292,17 @@ public class HttpUtil { | |||
| HttpPost httpPost = new HttpPost(url); | |||
| StringEntity entityStr = new StringEntity(xmlStr); | |||
| entityStr.setContentType("text/xml"); | |||
| System.out.println("entityStr--------------"+entityStr); | |||
| //logger.info("entityStr--------------"+entityStr); | |||
| httpPost.setEntity(entityStr); | |||
| CloseableHttpResponse response = httpclient.execute(httpPost); | |||
| try { | |||
| HttpEntity entity = response.getEntity(); | |||
| System.out.println("----------------------------------------"); | |||
| System.out.println(response.getStatusLine()); | |||
| //System.out.println("----------------------------------------"); | |||
| //System.out.println(response.getStatusLine()); | |||
| if (entity != null) { | |||
| System.out.println("Response content length: " + entity.getContentLength()); | |||
| //System.out.println("Response content length: " + entity.getContentLength()); | |||
| BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent())); | |||
| StringBuilder sb = new StringBuilder(); | |||
| String line = null; | |||