import java.io.BufferedInputStream;
import java.io.InputStream;
import java.net.URLConnection;
public class SSLConnection {
public void runTest( String url )
{
java.net.URL endpoint;
try
{
endpoint = new java.net.URL(url);
URLConnection connection = endpoint.openConnection();
InputStream in = new BufferedInputStream( connection.getInputStream() );
byte[] bytes = new byte[500];
int n = in.read(bytes, 0, 500 );
for ( int i = 0; i <>
System.out.print( new Character( (char) bytes[i] ) );
}
in.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main( String[] args )
{
SSLConnection test = new SSLConnection();
System.out.println("Connect without proxy - Non secure" );
test.runTest("http://your_url_goes_here");
System.out.println("Connect without proxy - Secure" );
test.runTest("https://your_url_goes_here");
System.setProperty("http.proxyHost", "your_proxy_name");
System.setProperty("http.proxyPort", "your_proxy_port");
System.out.println("Connect with proxy - Non secure" );
test.runTest("http://your_url_goes_here");
System.out.println("Connect with proxy - Secure" );
test.runTest("https://your_url_goes_here");
}
}
No comments:
Post a Comment