Solved

getting URL content from https sites

Posted on 2008-10-05
1
235 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
diffSum example 4 36
map related example 6 47
arguments to jar 5 26
mysql jsp example issue 32 32
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 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:

776 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