wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes about HTTPS connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "about HTTPS connection" Watch "about HTTPS connection" New topic
Author

about HTTPS connection

Mukunda s Dhakate
Greenhorn

Joined: Oct 29, 2007
Posts: 12
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
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
What is causing the timeout is not obvious from your code. See the comments at setReadTimeout

Some non-standard implementations of setReadTimeout ignore the timeout. The code may be not calling the server correctly. Has it worked before ? There are several possible matters involved.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about HTTPS connection