I am trying to post data to an HTTPS site.
I am using this code
try {
System.setProperty( "java.protocol.handler.pkgs" , "javax.net.ssl" );
java.security.Security.addProvider( new com.sun.net.ssl.internal.ssl.Provider() );
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager(){
public java.security.cert.X509Certificate[] getAcceptedIssuers(){
return null;
}
public void checkClientTrusted( java.security.cert.X509Certificate[] certs, String authType ) { }
public void checkServerTrusted( java.security.cert.X509Certificate[] certs, String authType ) { }
}
};
SSLContext sc = SSLContext.getInstance( "SSL" );
sc.init( null, trustAllCerts, new java.security.SecureRandom() );
HttpsURLConnection.setDefaultSSLSocketFactory( sc.getSocketFactory() );
URL url = new URL("https://www.google.com/adsense");
HttpURLConnection m_oHttpURLConnection = (HttpsURLConnection) url.openConnection();
m_oHttpURLConnection.setDoInput( true );
m_oHttpURLConnection.setDoOutput( true );
m_oHttpURLConnection.setUseCaches( false );
m_oHttpURLConnection.setRequestProperty( "Content-Type", "text/xml" );
// m_oHttpURLConnection.setAllowUserInteraction( true );
m_oHttpURLConnection.setRequestMethod( "POST" );
// m_oHttpURLConnection.setInstanceFollowRedirects( true );
m_oHttpURLConnection.connect();
} catch (Exception e){
e.printStackTrace();
}
executing this code I am getting Connection Timeout error,
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:516)
at java.net.Socket.connect(Socket.java:466)
at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:278)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:335)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:176)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:747)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:162)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:133)
Please help me find out the mistake