package com.mindprod.example;
import java.net.HttpURLConnection;
import java.net.URL;
import static java.lang.System.*;
/**
* Does an HTTP connect without reading anything. For experimenting with failed connections.
* <p/>
* Based on code by Arne Vajhøj arne@vajhoej.dk
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2016-07-10 initial version
* @since 2016-07-10
*/
public class TestConnection
{
public static void main( String[] args )
{
final String urlString = args[ 0 ];
probe( urlString );
}
public static void probe( String urlstr )
{
try
{
System.setProperty( "java.net.preferIPv4Stack", "true" );
System.setProperty( "jsse.enableSNIExtension", "false" );
System.setProperty( "jdk.tls.ephemeralDHKeySize", "2048" );
out.println( urlstr );
final URL url = new URL( urlstr );
final HttpURLConnection con = ( HttpURLConnection ) url.openConnection();
out.println( con.getHeaderFields() );
con.connect();
out.println( "\nreceived: ResponseCode: " + con.getResponseCode() +
" ContentLength: " + con.getContentLength() +
" ContentEncoding: " + con.getContentEncoding() );
con.disconnect();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}