Solved

getting URL content from https sites

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

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

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 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:

636 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