【发布时间】:2015-05-11 09:50:13
【问题描述】:
我正在尝试使用适用于 Android 的 GoogleMap api 在我的应用中创建地点搜索功能。我想在用户键入地点名称时填写 AutoComplete TextView。但是我在调用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)
以下是我正在使用的代码:
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;
}
我已在 Google 控制台中注册了我的应用程序包和系统的 SHA1。调用getPlaceUrl()方法后得到的url就是这种类型:
请帮我解决问题。
【问题讨论】:
-
@shayanpourvatan 这里的服务器是 GoogleMap 的服务器。我不认为
TLS 1.0 protocol支持不存在 -
您执行代码的设备/API 级别是什么? SSL/TLS 协议和密码取决于使用的操作系统。
-
@Robert 我正在 Lollypop/Kitkat 设备上执行代码,我使用 API 级别 19 来编译源代码
标签: java android ssl google-maps-android-api-2 google-maps-api-2