Solved

getting URL content from https sites

Posted on 2008-10-05
1
215 Views
Last Modified: 2012-05-05
hi

i have the follow code that works well when i try to get the content off non https sites like www.yahoo.com or www.google.com but when i  try to get the content from https sites it gives me an hostexception error. It seems that it is not able to get content from https sites. Any way to do this?
import java.net.*;

import java.io.*;
 

public class jget 

{

  public static void main ( String[] args ) throws IOException 

  {

    try 

    {

        URL url = new URL("http://www.yahoo.com");

    

        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

        String str;
 

        while ((str = in.readLine()) != null) 

        {

          System.out.println(str);

        }
 

        in.close();

    } 

    catch (MalformedURLException e) {} 

    catch (IOException e) {}

  }

}

Open in new window

0
Comment
Question by:jaxrpc
1 Comment
 
LVL 17

Accepted Solution

by:
Dejan Pažin earned 500 total points
ID: 22647468


Add this to your code:

System.setProperty("java.protocol.handler.pkgs",  "com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

Here is an explanation:
http://www.javaworld.com/javaworld/javatips/jw-javatip96.html
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
wordlen challenge 3 47
pairs challenge 5 44
create a gui in perl 3 45
Image decoding from Camera 3 45
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

758 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

23 Experts available now in Live!

Get 1:1 Help Now