Last active
February 3, 2019 05:39
-
-
Save AlainODea/6524217 to your computer and use it in GitHub Desktop.
Java Proxy Verfication - Simple URL Loader with no dependencies outside JavaSE
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.InputStream; | |
import java.io.InputStreamReader; | |
import java.io.Reader; | |
import java.net.URI; | |
import java.net.URL; | |
public class GetURL | |
{ | |
public static void main(String[] args) throws Exception | |
{ | |
URL url = URI.create(args[0]).toURL(); | |
try (InputStream inputStream = url.openStream(); | |
Reader reader = new InputStreamReader(inputStream); | |
BufferedReader bufferedReader = new BufferedReader(reader)) | |
{ | |
bufferedReader.lines().forEach(System.out::println); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiling:
Running with no proxy:
Running with system proxies:
Running with an explicit HTTP proxy:
Running with an explicit SOCKS proxy:
Troubleshooting
Accidentally using a SOCKS proxy as an HTTP proxy fails like this:
Accidentally using the wrong port or host fails like this (assuming the host or port is unreachable):
Reference
Read more Proxies - Networking Properties on Oracle's documentation site.