Socket Error in get https request

0

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

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

It worked fine, but 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 to give this error "java.net.SocketException: Connection reset".

    
asked by anonymous 26.10.2017 / 13:30

1 answer

0

HTTPS connections require "handshake" for the communication to function properly, so the server uses an HTTPS certificate that the client must use to make the connection, in this scenario using url.openStream will not work. Import the HTTPS certificate into the java keystore generalemten located in / lib / security / cacerts and use the HttpsURLConnection to connect

URL url = new URL("https://apidoni.ibpt.org.br/api/v1/produtos?");
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
InputStream is = con.getInputStream();
    
26.10.2017 / 15:20