2

I am trying to parse and manipulate HTML using jsoup. It is working perfectly fine for HTTP URLs but it's throwing UnknownHostException if a HTTPS URL is used. Following is my code:

System.setProperty("http.proxyHost", "192.168.0.1");
System.setProperty("http.proxyPort", "8080");

Document doc = Jsoup.connect("https://www.google.com/").get();

I was rather expecting an exception related to SSL certificates but what could be the reason for UnknownHostException? Please note that the following code runs perfectly for http://www.google.com/

2 Answers 2

5

Check here, you need to specify the proxy for https in a seperate way.

System.setProperty("https.proxyHost", "your host");
System.setProperty("https.proxyPort", "your port");
Sign up to request clarification or add additional context in comments.

5 Comments

are you sure? Because while working with HTTPConnections I never changed them explicitly for https urls.
Well from personal experience and from the linked documentation I'd say yes. Maybe in other projects the HTTP/HTTPS proxies were set universally, or added at runtime?
btw specifying these properties in standalone java application throws java.lang.ClassNotFoundException: Cannot find the specified class com.ibm.websphere.ssl.protocol.SSLSocketFactory. Any idea why is it referring to these files ?
Mostly guesswork, but it looks like your program tries to establish a HTTPS connection and therefor tries to call the servers default sslsocketfactory (to do the handshake). This fails though. Could be a configuration problem, could be a classpath problem.
+1 Yes, it was a classpath problem. Thanks a lot, it solved my problem :)
0

I am not sure if it helps you. I am using JSoup. consider this sample website,

String url = https://trickideas.com;

Jsoup.connect(url).get();

I get unknown host Exception if i try to connect to https://www.trickideas.com/

I don't get unknown host exception if i connect to https://trickideas.com/

I meddled with SSL certificates thinking that can be issue, but it wasn't. Issue was a simple typo.

Just check, if this is the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.