Java Android Developing "Failure In SSL Library, Usually A Protocol"
I'm programming an Application just for testing with Android Studio. I want to Request a Server with POST params which are in the string: (strings[0]). But I always get this Excep
Solution 1:
[...]
byte[] postData = strings[0].getBytes(StandardCharsets.UTF_8);
int postDataLength = postData.length;
URL url = new URL("https://example.com");
// The url has to be set to an international variable
new Thread(new Runnable() {
public void run() {
// The url has to be fetched from an international variable
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
//
conn.setDoOutput(true);
conn.setInstanceFollowRedirects(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("charset", "utf-8");
conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));
conn.setUseCaches(false);
//
// TLSv1 | TLSv1.1 | TLSv1.2
SSLContext sc = SSLContext.getInstance("TLSv1.2");
sc.init(null, null, new java.security.SecureRandom());
sc.getProtocol();
sc.getSupportedSSLParameters();
sc.getDefaultSSLParameters();
SSLEngine engine = sc.createSSLEngine();
conn.setSSLSocketFactory(sc.getSocketFactory());
conn.connect();
});
}
}).start();
try (final InputStream in = conn.getInputStream()) {
//…
}
[...]
https://developer.android.com/guide/components/processes-and-threads
Post a Comment for "Java Android Developing "Failure In SSL Library, Usually A Protocol""