Javax.net.ssl.SSLProtocolException when calling HttpUrlConnection.connect ()
I am trying to create a place finder function in my application using googlemap api for android. I want to populate the AutoComplete TextView as the user enters the place name. But I get this Excetion when called urlConnection.connect();
:
javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb911cd50: Failure in SSL library, usually a protocol error
error:1407743E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert inappropriate fallback (external/openssl/ssl/s23_clnt.c:765 0xae688edd:0x00000000)
Below is the code I am using:
private String downloadUrl(String strUrl) throws IOException {
String data = "";
InputStream iStream = null;
HttpURLConnection urlConnection = null;
try {
URL url = new URL(strUrl);
// Creating an http connection to communicate with url
urlConnection = (HttpURLConnection) url.openConnection();
// Connecting to url
urlConnection.connect();
// Reading data from url
iStream = urlConnection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(iStream));
StringBuffer sb = new StringBuffer();
String line = "";
while ((line = br.readLine()) != null) {
sb.append(line);
}
data = sb.toString();
br.close();
} catch (Exception e) {
Log.d("Exception while downloading url", e.toString());
} finally {
iStream.close();
urlConnection.disconnect();
}
return data;
}
private String getPlacesUrl(String qry) {
try {
qry = "input=" + URLEncoder.encode(qry, "utf-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
// Sensor enabled
String sensor = "sensor=false";
// place type to be searched
String types = "types=geocode";
// Building the parameters to the web service
String parameters = qry + "&" + types + "&" + sensor + "&" + mKey;
// Output format
String output = "json";
// Building the url to the web service
String url = "https://maps.googleapis.com/maps/api/place/autocomplete/" + output + "?" + parameters;
return url;
}
I have registered my app bundle and my system SHA1 on google console. The URL I get after calling the method getPlaceUrl()
is of the following type:
Please help me fix the problem.
source to share
I have almost the same problem. My logcat looks like this:
javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake canceled: ssl = 0x60b486b8: SSL library error, usually SSL procedure protocol error: SSL23_GET_SERVER_HELLO: tlsv1 warns of inappropriate sl / openss fallback ( /s23_clnt.c: 744 0x5ea50d74: 0x00000000)
Finally I found a solution to change the httpURLConnection.setHostnameVerifier HostnameVerifier to check the return value from false to true, but I don't know the reason. Are there any hints?
httpURLConnection.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// TODO Auto-generated method stub
// return false;
return true;
}
});
source to share