Solved

Connect to https site

Posted on 2002-07-23
4
451 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unhandled exception type Exception 18 65
passing enum to a method 4 50
Java List 4 76
How does initial implicit objects  are set up in JSP? 7 40
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

732 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