Created
November 12, 2012 22:18
-
-
Save pdeschen/4062370 to your computer and use it in GitHub Desktop.
Test Connection
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.*; | |
import java.net.*; | |
public class TestConnection { | |
public static void main(String[] args) throws IOException { | |
if (args.length == 0) { | |
System.err.println("Usage " + TestConnection.class.getCanonicalName() + " <url>"); | |
System.exit(-1); | |
} | |
URL url = new URL(args[0]); | |
URLConnection connection = url.openConnection(); | |
if (url.getUserInfo() != null) { | |
String basicAuth = "Basic " | |
+ javax.xml.bind.DatatypeConverter.printBase64Binary(url.getUserInfo().getBytes()); | |
connection.setRequestProperty("Authorization", basicAuth); | |
} | |
InputStream inputStream = connection.getInputStream(); | |
int in; | |
System.out.println(url.toExternalForm()); | |
System.out.println(">>>>"); | |
while ((in = inputStream.read()) != -1) { | |
System.out.write(in); | |
} | |
System.out.println(""); | |
System.out.flush(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
javac TestConnection.java
java TestConnection