Skip to content

Instantly share code, notes, and snippets.

@pdeschen
Created November 12, 2012 22:18
Show Gist options
  • Save pdeschen/4062370 to your computer and use it in GitHub Desktop.
Save pdeschen/4062370 to your computer and use it in GitHub Desktop.
Test Connection
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();
}
}
@pdeschen
Copy link
Author

javac TestConnection.java
java TestConnection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment