|
5 | 5 | import org.apache.commons.httpclient.methods.GetMethod; |
6 | 6 | import org.apache.commons.io.IOUtils; |
7 | 7 | import org.apache.http.HttpResponse; |
8 | | -import org.apache.http.client.config.RequestConfig; |
9 | 8 | import org.apache.http.client.fluent.Request; |
10 | 9 | import org.apache.http.client.methods.HttpGet; |
11 | 10 | import org.apache.http.impl.client.CloseableHttpClient; |
|
21 | 20 | import javax.imageio.ImageIO; |
22 | 21 | import java.io.BufferedReader; |
23 | 22 | import java.io.IOException; |
| 23 | +import java.io.InputStream; |
24 | 24 | import java.io.InputStreamReader; |
25 | 25 | import java.net.HttpURLConnection; |
26 | 26 | import java.net.URI; |
|
33 | 33 | */ |
34 | 34 | public class HttpUtils { |
35 | 35 |
|
36 | | - private static Logger logger = LoggerFactory.getLogger(HttpUtils.class); |
| 36 | + private final static Logger logger = LoggerFactory.getLogger(HttpUtils.class); |
37 | 37 |
|
38 | 38 | public static String commonHttpClient(String url) { |
39 | 39 |
|
@@ -110,12 +110,14 @@ public static String URLConnection(String url) { |
110 | 110 | } |
111 | 111 |
|
112 | 112 |
|
113 | | - public static String HTTPURLConnection(String url) { |
| 113 | + public static String HttpURLConnection(String url) { |
114 | 114 | try { |
115 | 115 | URL u = new URL(url); |
116 | 116 | URLConnection urlConnection = u.openConnection(); |
117 | | - HttpURLConnection httpUrl = (HttpURLConnection) urlConnection; |
118 | | - BufferedReader in = new BufferedReader(new InputStreamReader(httpUrl.getInputStream())); //send request |
| 117 | + HttpURLConnection conn = (HttpURLConnection) urlConnection; |
| 118 | + // Many HttpURLConnection methods can send http request, such as getResponseCode, getHeaderField |
| 119 | + InputStream is = conn.getInputStream(); // send request |
| 120 | + BufferedReader in = new BufferedReader(new InputStreamReader(is)); |
119 | 121 | String inputLine; |
120 | 122 | StringBuilder html = new StringBuilder(); |
121 | 123 |
|
@@ -206,7 +208,6 @@ public static String HttpAsyncClients(String url) { |
206 | 208 | logger.error(e.getMessage()); |
207 | 209 | } |
208 | 210 | } |
209 | | - |
210 | 211 | } |
211 | 212 |
|
212 | 213 | } |
0 commit comments