Solved

Connect to https site

Posted on 2002-07-23
4
447 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
Comment Utility
0
 

Expert Comment

by:hi_billy
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now