@@ -44,8 +44,6 @@ public static String httpRequest(String requestUrl, int timeOut, String requestM
44
44
if (!requestUrl .contains ("http" )) {
45
45
requestUrl = "http://" + requestUrl ;
46
46
}
47
- //代理
48
- Proxy proxy = (Proxy ) MainController .settingInfo .get ("proxy" );
49
47
50
48
try {
51
49
URL url = new URL (requestUrl );
@@ -55,6 +53,8 @@ public static String httpRequest(String requestUrl, int timeOut, String requestM
55
53
TrustManager [] tm = { new fun .fireline .tools .MyCERT () };
56
54
sslContext .init (null , tm , new SecureRandom ());
57
55
SSLSocketFactory ssf = sslContext .getSocketFactory ();
56
+ //代理
57
+ Proxy proxy = (Proxy ) MainController .settingInfo .get ("proxy" );
58
58
59
59
if (proxy != null ) {
60
60
hsc = (HttpsURLConnection )url .openConnection (proxy );
@@ -65,6 +65,9 @@ public static String httpRequest(String requestUrl, int timeOut, String requestM
65
65
hsc .setHostnameVerifier (allHostsValid );
66
66
httpUrlConn = hsc ;
67
67
} else {
68
+ //代理
69
+ Proxy proxy = (Proxy ) MainController .settingInfo .get ("proxy" );
70
+
68
71
if (proxy != null ) {
69
72
hc = (HttpURLConnection )url .openConnection (proxy );
70
73
} else {
@@ -82,7 +85,6 @@ public static String httpRequest(String requestUrl, int timeOut, String requestM
82
85
if (contentType != null && !"" .equals (contentType ))
83
86
httpUrlConn .setRequestProperty ("Content-Type" , contentType );
84
87
85
-
86
88
httpUrlConn .setRequestProperty ("User-Agent" , "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)" );
87
89
httpUrlConn .setRequestProperty ("Accept" , "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" );
88
90
httpUrlConn .setRequestProperty ("Accept-Encoding" , "gzip, deflate" );
@@ -104,14 +106,14 @@ public static String httpRequest(String requestUrl, int timeOut, String requestM
104
106
String result = readString (inputStream , encoding );
105
107
return result ;
106
108
} catch (IOException ie ) {
107
- logger .error (ie . getStackTrace () );
109
+ logger .error (ie );
108
110
if (hsc != null )
109
111
return readString (hsc .getErrorStream (), encoding );
110
112
if (hc != null )
111
113
return readString (hc .getErrorStream (), encoding );
112
114
return "" ;
113
115
} catch (Exception e ) {
114
- logger .error (e . getStackTrace () );
116
+ logger .error (e );
115
117
throw e ;
116
118
} finally {
117
119
if (hsc != null )
@@ -212,10 +214,10 @@ public static String headerByHttpRequest(String requestUrl, int timeOut, String
212
214
}
213
215
return "" ;
214
216
} catch (IOException e ) {
215
- logger .error (e . getStackTrace () );
217
+ logger .error (e );
216
218
throw e ;
217
219
} catch (Exception e ) {
218
- logger .error (e . getStackTrace () );
220
+ logger .error (e );
219
221
throw e ;
220
222
} finally {
221
223
if (br != null )
@@ -250,7 +252,7 @@ public static String readString(InputStream inputStream, String encoding) throws
250
252
}
251
253
252
254
} catch (IOException e ) {
253
- logger .error (e . getStackTrace () );
255
+ logger .error (e );
254
256
} finally {
255
257
if (baos != null ) {
256
258
baos .flush ();
@@ -362,7 +364,7 @@ public static String httpRequestAddHeader(String requestUrl, int timeOut, String
362
364
if (hc != null ) {
363
365
hc .disconnect ();
364
366
}
365
- logger .error (e . getStackTrace () );
367
+ logger .error (e );
366
368
throw e ;
367
369
}
368
370
@@ -388,7 +390,7 @@ public static String ImageToBase64ByOnline(String imgURL) {
388
390
// 关闭流
389
391
is .close ();
390
392
} catch (IOException e ) {
391
- logger .error (e . getStackTrace () );
393
+ logger .error (e );
392
394
e .printStackTrace ();
393
395
}
394
396
// 对字节数组Base64编码
@@ -462,10 +464,10 @@ public static int codeByHttpRequest(String requestUrl, int timeOut, String reque
462
464
return hc .getResponseCode ();
463
465
return 0 ;
464
466
} catch (IOException e ) {
465
- logger .error (e . getStackTrace () );
467
+ logger .error (e );
466
468
throw e ;
467
469
} catch (Exception e ) {
468
- logger .error (e . getStackTrace () );
470
+ logger .error (e );
469
471
throw e ;
470
472
} finally {
471
473
if (br != null )
@@ -582,7 +584,7 @@ public static boolean downloadFile(String downURL, File file) throws Exception {
582
584
out .write (buf , 0 , size );
583
585
}
584
586
} catch (Exception e ) {
585
- logger .error (e . getStackTrace () );
587
+ logger .error (e );
586
588
throw e ;
587
589
} finally {
588
590
if (bin != null )
0 commit comments