• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing HTTPS URL through SSL - fails with UnknownHostException

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to access HTTPS URL through SSL. Below is my code. But it continuously throw UnknownHostException. Can someone help me out with this?

import java.net.URL;
import java.net.URLConnection;
import java.security.Security;

public class TestSSL {
public static void main(String[] args) {
System.getProperties().put("http.proxyHost", "XXX");
System.getProperties().put("http.proxyPort", "XXX");
System.out.println("bfr");
System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
System.out.println("1");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
System.out.println("2");
try {


//System.getProperties().put("java.protocol.handler.pkgs", "HTTPClient");
//URL url = new URL("https://www.verisign.com/";);



URL url = new URL("https://www.verisign.com/";);
System.out.println("3");
URLConnection con = url.openConnection();
System.out.println("4");
con.connect();
//java.io.InputStream urlfs = con.getInputStream();
System.out.println("5");
System.out.println("Successful Connection Establishment");

} catch (Exception e) {
System.out.println("Print Exception Details =>"+e.toString());
}

}
}
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Presumably your real code doesn't have

System.getProperties().put("http.proxyHost", "XXX");

but the real proxy host name? If so, have you absolutely confirmed that it's correct?
 
Geetha Gubendran
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do have it in my real code. I tried setting my username and password as well. But no use.
 
Geetha Gubendran
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This has been fixed by setting

System.getProperties().put("https.proxyHost", "XXX");
System.getProperties().put("https.proxyPort", "XXX");


instead of

System.getProperties().put("http.proxyHost", "XXX");
System.getProperties().put("http.proxyPort", "XXX");

Thanks,
Raj
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic