|
@@ -1,5 +1,6 @@
|
|
|
package com.ozs.common.utils.http;
|
|
|
|
|
|
+import java.io.BufferedInputStream;
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
@@ -11,14 +12,17 @@ import java.net.URL;
|
|
|
import java.net.URLConnection;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.security.cert.X509Certificate;
|
|
|
+
|
|
|
import javax.net.ssl.HostnameVerifier;
|
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
|
import javax.net.ssl.SSLContext;
|
|
|
import javax.net.ssl.SSLSession;
|
|
|
import javax.net.ssl.TrustManager;
|
|
|
import javax.net.ssl.X509TrustManager;
|
|
|
+
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
import com.ozs.common.constant.Constants;
|
|
|
import com.ozs.common.utils.StringUtils;
|
|
|
|
|
@@ -64,7 +68,6 @@ public class HttpUtils
|
|
|
*/
|
|
|
public static String sendGet(String url, String param, String contentType)
|
|
|
{
|
|
|
- StringBuilder result = new StringBuilder();
|
|
|
BufferedReader in = null;
|
|
|
try
|
|
|
{
|
|
@@ -76,15 +79,21 @@ public class HttpUtils
|
|
|
connection.setRequestProperty("connection", "Keep-Alive");
|
|
|
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
|
|
connection.connect();
|
|
|
- log.info("connection.getInputStream() - {}", connection.getInputStream());
|
|
|
+ InputStream inputStream = connection.getInputStream();
|
|
|
+ log.info("size {}", inputStream.available());
|
|
|
log.info("contentType - {}", contentType);
|
|
|
- in = new BufferedReader(new InputStreamReader(connection.getInputStream(), contentType));
|
|
|
- String line;
|
|
|
- while ((line = in.readLine()) != null)
|
|
|
- {
|
|
|
- result.append(line);
|
|
|
+ BufferedInputStream bufIs = new BufferedInputStream(inputStream);
|
|
|
+
|
|
|
+ byte[] buf = new byte[inputStream.available()];
|
|
|
+ int len = bufIs.read(buf);
|
|
|
+ if (len < 0) {
|
|
|
+ return "";
|
|
|
}
|
|
|
+
|
|
|
+ String result = new String(buf, contentType);
|
|
|
log.info("recv - {}", result);
|
|
|
+
|
|
|
+ return result;
|
|
|
}
|
|
|
catch (ConnectException e)
|
|
|
{
|
|
@@ -116,7 +125,7 @@ public class HttpUtils
|
|
|
log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
|
|
|
}
|
|
|
}
|
|
|
- return result.toString();
|
|
|
+ return "";
|
|
|
}
|
|
|
|
|
|
/**
|