Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HttpsURLConnection not working

843811Apr 20 2004 — edited May 13 2008
Hello, I have been trying to solve this problem for a long time now. I have a class that uses HttpsURLConnection to retrieve data via SSL URL. I have looked at the previous posts and have tried everything. Someone before mentioned to upgrade the JDK. I did that also, I now have JDK 1.4.2_04. I looked at the documentation from "http://java.sun.com/developer/technicalArticles/Security/secureinternet2/". I tried the example and it worked because the URL used was https://www.sun.com. When I use it with my remote server it does not work. I tested the URL on my browser and it works so I know the remote server is enabled with SSL. I don't know what else to do. Can someone please shine some light into this subject for me. Below is somewhat my code:

import java.io.*;
import java.net.*;
import javax.net.ssl.*;

public class ...{

public static void main (String[] args){
URL url;
StringBuffer buffer;
String line;
int responseCode=0;
HttpsURLConnection connection = null;
InputStream input;
BufferedReader dataInput;
String nurl = ".................."; //My URL
try {
url = new URL(nurl);
connection = (HttpsURLConnection) url.openConnection();
responseCode = connection.getResponseCode();
}
catch (Exception e){System.err.println(e);}

try {
buffer = new StringBuffer();
input = connection.getInputStream();
dataInput =
new BufferedReader(new InputStreamReader(input));
while ((line = dataInput.readLine()) != null) {
buffer.append(line);
buffer.append('\n');
}
complete = (String) buffer.toString().trim();
} catch (Exception e){System.err.println(e);}
System.out.println(complete);
}

}

ERROR:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found
java.io.IOException
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 10 2008
Added on Apr 20 2004
11 comments
1,629 views