Good day, may ask for advice. My code is worked properly, but one day for no apparent reason and without changes to the code on the server stopped working, displaying this error I have checked the decisions referred to by links, but none of them gave the desired result. Perhaps there was something in the SSL protocol?
Safely fixing: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
javax.net.ssl.sslpeerunverifiedexception no peer certificate
Android ssl: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
Trusting all certificates using HttpClient over HTTPS
class RequestTask extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
try {
HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
DefaultHttpClient client = new DefaultHttpClient();
SchemeRegistry registry = new SchemeRegistry();
SSLSocketFactory socketFactory = SSLSocketFactory
.getSocketFactory();
socketFactory
.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
registry.register(new Scheme("https", socketFactory, 443));
SingleClientConnManager mgr = new SingleClientConnManager(
client.getParams(), registry);
DefaultHttpClient httpClient = new DefaultHttpClient(mgr,
client.getParams());
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
ResponseHandler<String> res = new BasicResponseHandler();
HttpPost postMethod = new HttpPost("https://api.equalibra.net/banners.json");
nameValuePairs.add(new BasicNameValuePair("lang", "rus"));
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs,
HTTP.UTF_8));
String response = "";
try {
response = httpClient.execute(postMethod, res);
} catch (Exception e) {
Log.d("my", e.toString());
}
JSONURL(response);
} catch (Exception e) {
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
}