How do I retrieve a URL in Java?

How can I simulate the behavior of curl -k <url> in Java?

  • I'm trying to poll a HTTPS URL on a local server, but cannot due to security certificate issues. If I try to 'curl' it on CLI, still it would complain. See here: However, on CLI I can successfully get the content if I use curl with -k option. The code I'm currently using is: HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); InputStream is = connection.getInputStream(); How can I change this so it would fetch it 'insecurly', like curl does with -k option?

  • Answer:

    You can use SSLSocketFactory in connection with HTTPSURLConnection as described here http://stackoverflow.com/questions/859111/how-do-i-accept-a-self-signed-certificate-with-a-java-httpsurlconnection

Asher Syed at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.