I'm having trouble figuring out how to interact with an HTTPS site from a Java application (not applet or server-side) and submit some forms until I get to the page I need to parse for some data. In order to make sure I could figure out how to do *something*, I followed some O'Reilly Network Programming code for posting to a website (pg. 500-501) and created a Java application that can interact with http://www.weather.com and submit my local zip code and get the HTML from the result page. From there I tried to modify it to interact with the HTTPS site. I wasn't sure what I needed to change, especially with the following line:
URLConnection uc = url.openConnection();
However, I found this code online and decided to put it in after the above line:
Because the URL I hardcoded is an https one, it prints out "very good", so I know it's automatically giving me an HttpsURLConnection.
I also used Authenticator.setDefault(mySpecificAuthenticatorSubclass());
However, when I run the code to try to interact with the site, I get this:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found
So, I'm clearly not authenticating properly or something like that. Any ideas? This is actually about the 3rd approach I've taken in the past week, and I'm getting pretty frustrated!
I have a similar situation to the one describe here. I have been hunting for a solution now for about a week.
The application works perfectly with a Http connection, but does nothing and generates an exception when using Https.
Here are the stack traces:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275) at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275) at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275) at com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(DashoA6275) at sun.net.www.protocol.https.HttpsClient.afterConnect(DashoA6275) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(DashoA627 5) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.j ava:558) at com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl.getOutput Stream(DashoA6275) at com.unitrin.ami.test.AmiClient.sendRequest(AmiClient.java:129)
You might need JSSE (Java Secure Sockets Extension version 1.0.3) api or above to implement the https thing. JSSE is a set of Java packages that enable secure Internet communications.