Solved

Connect to https site

Posted on 2002-07-23
4
450 Views
Last Modified: 2010-03-31
I want to connect to Https site, for this sample code,when connec to https://www.verisign.com everything is alright. But when I wanna to connect to another https(example, https://www.ep.com.my), I get an exception saying
Exception in thread "main" javax.net.ssl.SSLHandshakeException: Could not find trusted certificate.

how to solve this problem. URGENT. thankss

public class Test {
    public static void main(String[] args) throws Exception {
     URL site = new URL("https://www.verisign.com/");    
     BufferedReader in = new BufferedReader(
                    new InputStreamReader(
                    site.openStream()));

     String inputLine;

     while ((inputLine = in.readLine()) != null)
         System.out.println(inputLine);

     in.close();
    }
}
0
Comment
Question by:cHEo
4 Comments
 
LVL 4

Accepted Solution

by:
antons061400 earned 100 total points
ID: 7173508
0
 

Expert Comment

by:hi_billy
ID: 7213829
i think you are using older version of JDK....right?....
if you want to make a connection to https site, you must import the JSSE package(http://java.sun.com/products/jsse/). and modify your code like this :


import javax.net.ssl.*;
import any.other.package;

public class Test {
   public static void main(String[] args) throws Exception {
System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");

java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

    URL site = new URL("https://www.verisign.com/");    
    BufferedReader in = new BufferedReader(
                   new InputStreamReader(
                   site.openStream()));

    String inputLine;

    while ((inputLine = in.readLine()) != null)
        System.out.println(inputLine);

    in.close();
   }
}



hopes this help...:-)
0
 
LVL 35

Expert Comment

by:girionis
ID: 8951730
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- points to antons

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question