调用HttpUrlConnection.connect()时的javax.net.ssl.SSLProtocolException

调用HttpUrlConnection.connect()时的javax.net.ssl.SSLProtocolException,java,android,ssl,google-maps-android-api-2,google-maps-api-2,Java,Android,Ssl,Google Maps Android Api 2,Google Maps Api 2,我正在尝试使用谷歌地图的Android api在我的应用程序中创建位置搜索功能。我想在用户键入地点名称时填写自动完成文本视图。但是我在调用urlConnection.connect()时得到了这个异常语句: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb911cd50: Failure in SSL library, usually a protocol error error:1407743E:SSL rou

我正在尝试使用谷歌地图的Android api在我的应用程序中创建位置搜索功能。我想在用户键入地点名称时填写自动完成文本视图。但是我在调用
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;
    }
我已经在谷歌控制台上注册了我的应用软件包和系统的SHA1。调用
getPlaceUrl()
方法后得到的url属于以下类型:

请帮我解决这个问题。

我遇到了一个几乎相同的问题。 我的日志如下:

javax.net.ssl.SSLHandshakeException:javax.net.ssl.SSLProtocolException: SSL握手中止:SSL=0x60b486b8:SSL库中出现故障,通常是协议错误 SSL例程:SSL23\u GET\u SERVER\u HELLO:tlsv1警报不适当回退(外部/openssl/SSL/s23\u clnt.c:744 0x5ea50d74:0x00000000)

最后,我找到了一个解决方案,将httpURLConnection.setHostnameVerifier HostnameVerifier验证返回值从false修改为true,但我不知道根本原因。 有人能提供小费吗

        httpURLConnection.setHostnameVerifier(new HostnameVerifier() {
            @Override
            public boolean verify(String hostname, SSLSession session) {
                // TODO Auto-generated method stub
                // return false;
                return true;
            }
        });

看见可能是helpful@shayanpourvatan这里的服务器是谷歌地图的服务器。我不认为TLS 1.0协议不支持,你执行代码的设备/API级别是什么?SSL/TLS协议和密码取决于所使用的操作系统。@Robert我正在Lollypop/Kitkat设备上执行代码,我正在使用API级别19来编译源代码您可能是指
HttpsURLConnection