I need to create application for my customer, and one part from app uses https connection:
public static void getVersions() throws IOException, ParserConfigurationException, SAXException {
URL u = new URL(VERSION_URL);
HttpsURLConnection c = (HttpsURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
InputStream in = c.getInputStream();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
builder = factory.newDocumentBuilder();
Document d = builder.parse(in);
}
But when I try to use it I will got IO Exception: “No trusted certificate java”. It’s service of my customer, all is legal. How can I fix this bug?
You can put the custom server certificate in a trust store and include it as resource within your application.
When creating the HTTPS connection to that server you can specify that this trust store contains certificates that are trusted. That can be done by creating your own SSLSocketFactory instance
See also: How Can I Access an SSL Connection Through Android?