I have to access a Https API. It works just fine with Postman and with the Android Asynchronous Http Client library.
But when I try it on a desktop java application it just says:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
javax.servlet.ServletException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420) com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558) com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733) javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
My non-working desktop code:
HttpURLConnection con;
String response;
try {
con = (HttpURLConnection) new URL(LOGIN_URL).openConnection();
con.setDoOutput(true);
con.setRequestMethod("GET");
OutputStream os = con.getOutputStream(); //throws error
os.flush();
return "200";
} catch (Exception e) {
e.printStackTrace();
return e.toString();
}
My Android working code:
AsyncHttpClient client = new AsyncHttpClient();
RequestParams rp = new RequestParams();
client.get("LOGIN_URL", rp, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
return new String(response); //works
}
});
So, my question here is: If it is possible to make it run on Android, why is not working with Apache HttpComponents or the HttpURLConnection methods?
Is there any library I can use without installing any certificates which works just like on Android? I just want to trust the web service without it for several reasons.