|
|
@@ -73,13 +73,22 @@ public class HttpUtil { |
|
|
|
|
|
|
|
public static InputStream get (String urlString) throws IOException { return get(urlString, null); } |
|
|
|
|
|
|
|
public static InputStream get (String urlString, long connectTimeout) throws IOException { |
|
|
|
return get(urlString, null, null, connectTimeout); |
|
|
|
} |
|
|
|
|
|
|
|
public static InputStream get (String urlString, Map<String, String> headers) throws IOException { |
|
|
|
return get(urlString, headers, null); |
|
|
|
} |
|
|
|
|
|
|
|
public static InputStream get (String urlString, Map<String, String> headers, Map<String, String> headers2) throws IOException { |
|
|
|
return get(urlString, headers, headers2, null); |
|
|
|
} |
|
|
|
|
|
|
|
public static InputStream get (String urlString, Map<String, String> headers, Map<String, String> headers2, Long connectTimeout) throws IOException { |
|
|
|
final URL url = new URL(urlString); |
|
|
|
final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); |
|
|
|
if (connectTimeout != null) urlConnection.setConnectTimeout(connectTimeout.intValue()); |
|
|
|
if (headers != null) addHeaders(urlConnection, headers); |
|
|
|
if (headers2 != null) addHeaders(urlConnection, headers2); |
|
|
|
return urlConnection.getInputStream(); |
|
|
@@ -198,6 +207,13 @@ public class HttpUtil { |
|
|
|
return out.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
public static String url2string (String url, long connectTimeout) throws IOException { |
|
|
|
@Cleanup final InputStream in = get(url, connectTimeout); |
|
|
|
final ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
|
IOUtils.copy(in, out); |
|
|
|
return out.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
public static HttpResponseBean getResponse(HttpRequestBean requestBean) throws IOException { |
|
|
|
final HttpClientBuilder clientBuilder = requestBean.initClientBuilder(HttpClients.custom()); |
|
|
|
@Cleanup final CloseableHttpClient client = clientBuilder.build(); |
|
|
|