|
@@ -9,6 +9,7 @@ import java.net.ConnectException;
|
|
|
import java.net.SocketTimeoutException;
|
|
|
import java.net.URL;
|
|
|
import java.net.URLConnection;
|
|
|
+import java.security.cert.CertificateException;
|
|
|
import java.security.cert.X509Certificate;
|
|
|
import java.text.ParseException;
|
|
|
import javax.net.ssl.HostnameVerifier;
|
|
@@ -54,6 +55,7 @@ public class HttpUtils
|
|
|
String urlNameString = url;
|
|
|
log.info("sendGet - {}", urlNameString);
|
|
|
URL realUrl = new URL(urlNameString);
|
|
|
+
|
|
|
URLConnection connection = realUrl.openConnection();
|
|
|
connection.setRequestProperty("accept", "*/*");
|
|
|
connection.setRequestProperty("connection", "Keep-Alive");
|
|
@@ -117,6 +119,7 @@ public class HttpUtils
|
|
|
String urlNameString = url + "?" + param;
|
|
|
log.info("sendPost - {}", urlNameString);
|
|
|
URL realUrl = new URL(urlNameString);
|
|
|
+
|
|
|
URLConnection conn = realUrl.openConnection();
|
|
|
conn.setRequestProperty("accept", "*/*");
|
|
|
conn.setRequestProperty("connection", "Keep-Alive");
|
|
@@ -189,6 +192,7 @@ public class HttpUtils
|
|
|
{
|
|
|
log.info("sendPost - {}", url);
|
|
|
URL realUrl = new URL(url);
|
|
|
+
|
|
|
URLConnection conn = realUrl.openConnection();
|
|
|
conn.setRequestProperty("accept", "*/*");
|
|
|
conn.setRequestProperty("connection", "Keep-Alive");
|
|
@@ -244,7 +248,67 @@ public class HttpUtils
|
|
|
}
|
|
|
return result.toString();
|
|
|
}
|
|
|
+ public static String sendSSLGet(String url)
|
|
|
+ {
|
|
|
+ StringBuilder result = new StringBuilder();
|
|
|
+ BufferedReader in = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ String urlNameString = url;
|
|
|
+ log.info("sendSSLGet - {}", urlNameString);
|
|
|
+ SSLContext sc = SSLContext.getInstance("SSL");
|
|
|
+ sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom());
|
|
|
+ URL realUrl = new URL(urlNameString);
|
|
|
|
|
|
+ HttpsURLConnection connection = (HttpsURLConnection)realUrl.openConnection();
|
|
|
+ connection.setRequestProperty("accept", "*/*");
|
|
|
+ connection.setRequestProperty("connection", "Keep-Alive");
|
|
|
+ connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
|
|
+
|
|
|
+ connection.setSSLSocketFactory(sc.getSocketFactory());
|
|
|
+ connection.setHostnameVerifier(new TrustAnyHostnameVerifier());
|
|
|
+
|
|
|
+ connection.connect();
|
|
|
+ in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
|
+ String line;
|
|
|
+ while ((line = in.readLine()) != null)
|
|
|
+ {
|
|
|
+ result.append(line);
|
|
|
+ }
|
|
|
+ log.info("recv - {}", result);
|
|
|
+ }
|
|
|
+ catch(ConnectException e)
|
|
|
+ {
|
|
|
+ log.error("调用HttpUtils.sendGet ConnectException, url=" + url , e);
|
|
|
+ }
|
|
|
+ catch (SocketTimeoutException e)
|
|
|
+ {
|
|
|
+ log.error("调用HttpUtils.sendGet SocketTimeoutException, url=" + url , e);
|
|
|
+ }
|
|
|
+ catch (IOException e)
|
|
|
+ {
|
|
|
+ log.error("调用HttpUtils.sendGet IOException, url=" + url, e);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ log.error("调用HttpsUtil.sendGet Exception, url=" + url , e);
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (in != null)
|
|
|
+ {
|
|
|
+ in.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ log.error("调用in.close Exception, url=" + url , ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result.toString();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
public static String sendSSLPost(String url, String param)
|
|
@@ -257,6 +321,7 @@ public class HttpUtils
|
|
|
SSLContext sc = SSLContext.getInstance("SSL");
|
|
|
sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom());
|
|
|
URL console = new URL(urlNameString);
|
|
|
+
|
|
|
HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
|
|
|
conn.setRequestProperty("accept", "*/*");
|
|
|
conn.setRequestProperty("connection", "Keep-Alive");
|