Socket Error in get https request

Asked

Viewed 178 times

0

I use Java 6. I was doing the integration with IBPT and I used this code:

URL url = new URL("http://iws.ibpt.org.br/api/deolhonoimposto/Produtos?");
InputStream input = url.openStream(); 

It worked right, only the web service changed and now the url uses https:

URL url = new URL("https://apidoni.ibpt.org.br/api/v1/produtos?");
InputStream input = url.openStream();

And started giving this error "java.net.Socketexception: Connection reset".

1 answer

0

HTTPS connections need "Handshake" for the communication to work properly, for this the server uses an HTTPS certificate that must be used by the client to make the connection, in this scenario using url.openStream will not work. Import the HTTPS certificate to the java geralemten Keystore /lib/security/cacerts and use the class Httpsurlconnection to connect

URL url = new URL("https://apidoni.ibpt.org.br/api/v1/produtos?");
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
InputStream is = con.getInputStream();
  • And how would I pick up the value from within the connection? con.getInputStream()?

  • That’s right, I edited the answer with an example

  • Vixi, continues the same error: 13:44:48,238 ERROR [STDERR] java.net.Socketexception: Connection reset

  • I think the certificate is missing.

  • managed to resolve this issue as?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.