新增代理

This commit is contained in:
2023-02-27 20:48:09 +08:00
parent 0819bc58aa
commit a27d6c5a35
2 changed files with 27 additions and 15 deletions

View File

@@ -17,7 +17,7 @@ public class HttpTools {
private static final int HttpRequestIndex = 3;
public static String get(String url) {
return http_get(url, null);
return http_get(url, null,false);
}
public static String post(final String url, final byte[] body) {
@@ -40,10 +40,19 @@ public class HttpTools {
return null;
}
public static String http_get(String url, Map<String, String> header) {
public static String http_get(String url, Map<String, String> header,boolean isProxy) {
try {
HttpURLConnection connection;
connection = (HttpURLConnection) new URL(url).openConnection();
Proxy proxy = null;
if (isProxy) {
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7890));
}
if(proxy==null) {
connection = (HttpURLConnection) new URL(url).openConnection();
}else{
connection = (HttpURLConnection) new URL(url).openConnection(proxy);
}
return urlConnection(header, connection);
} catch (Exception e) {
System.err.println("error url = " + url);