Help and Support
 

powered byLive Search

PRB: Allowing the URL class to Access HTTPS in Applications

Article ID:191120
Last Review:July 14, 2004
Revision:2.1
This article was previously published under Q191120
On This Page

SYMPTOMS

Attempting to open a HTTPS: URL in an application with the default URLStreamHandler will result in the following error message being generated:
java.net.MalformedURLException: unknown protocol: https at java/net/URL.<init> (URL.java)

Back to the top

CAUSE

The default URLStreamHandler for applications does not have the ability to access a URL via the HTTPS: protocol.

Back to the top

RESOLUTION

The com.ms.net.wininet.WininetStreamHandlerFactory class can be used to allow applications to access an HTTPS: URL. In an application, you can set the URLStreamHandlerFactory using the following command:
   java.net.URL.setURLStreamHandlerFactory(
      new com.ms.net.wininet.WininetStreamHandlerFactory());
				

Back to the top

STATUS

This behavior is by design.

Back to the top

MORE INFORMATION

The following Sample code demonstrates how to use the WininetStreamHandlerFactory in a Java application. You should change the line 'String page="..."' to point to a valid HTTPS Web server.

Back to the top

Sample Code

   import java.net.*;
   import java.io.*;

   public class HTTPS
   {

     public static void main(String args[]) {
   /*
     Install a URLStreamHandler that can handle the HTTPS: protocol.
   */ 
       try {
         if (Class.forName(
               "com.ms.net.wininet.WininetStreamHandlerFactory" )!=null)
           URL.setURLStreamHandlerFactory(new
               com.ms.net.wininet.WininetStreamHandlerFactory());
       } catch (ClassNotFoundException ex) {
         System.err.println(
           "Warning: WininetStreamHandlerFactory class not found.");
       }

       try {
   /*
     The following line assumes that you have a HTTPS: server on your
     local machine, with a Login.ASP page in the root directory. You
     can replace the following line with any valid HTTPS: URL.
   */ 
         String page="https://localhost/Login.asp";
         URL url=new URL(page);
         URLConnection connection=url.openConnection();
         connection.setAllowUserInteraction(true);
         DataInputStream dis=new DataInputStream(
                                   connection.getInputStream());
         String input;
         do {
           input=dis.readLine();
           if (input!=null)
           System.out.println(input);
         } while (input!=null);
         dis.close();
       } catch (IOException ex) {
         System.err.println("IOException, make sure the URL is valid.");
         ex.printStackTrace();
       }
     }
   }
				
(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Derek Jamison, Microsoft Corporation

Back to the top


APPLIES TO
Microsoft Software Development Kit for Java 2.02
Microsoft Software Development Kit for Java 2.01
Microsoft Software Development Kit for Java 3.0

Back to the top

Keywords: 
kbnetwork kbjava kbprb KB191120

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.