Created
December 22, 2016 08:04
-
-
Save ripla/085a0d6bf34a076dc138931e7bda164a to your computer and use it in GitHub Desktop.
Simple URL connection checker for proxied connections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.net.InetSocketAddress; | |
import java.net.Proxy; | |
import java.net.URL; | |
import java.net.URLConnection; | |
import java.util.stream.Collectors; | |
public class UrlChecker { | |
public static void main(String[] args) { | |
if (args.length != 3) { | |
System.out.println( | |
"Usage: " + UrlChecker.class.getName() + " " + | |
"<url> <proxy> <port>"); | |
System.exit(1); | |
} | |
try { | |
String url = args[0]; | |
String proxyHost = args[1]; | |
int proxyPort = Integer.parseInt(args[2]); | |
Proxy proxy = new Proxy(Proxy.Type.HTTP, | |
new InetSocketAddress(proxyHost, proxyPort)); | |
URLConnection con = new URL(url).openConnection(proxy); | |
try (BufferedReader br = new BufferedReader( | |
new InputStreamReader(con.getInputStream()))) { | |
System.out.println(br.lines() | |
.collect(Collectors.joining(System.lineSeparator()))); | |
} | |
} catch (Exception exception) { | |
exception.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment