0

我有一个与 Web 服务器通信以检索一些数据的应用程序,该应用程序始终运行良好,但现在显示此错误:

javax.net.ssl.SSLException:连接被对等方关闭

这只发生在我使用 android < 4.4 if is 6.0 > 它工作正常时

 public void volleyJsonObjectRequest(String url){

    String  REQUEST_TAG = "com.androidtutorialpoint.volleyJsonObjectRequest";
    pDialog = new ProgressDialog(LoginActivity.this);
    pDialog.setMessage("Efetuando login..");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    pDialog.show();

    StringRequest postRequest = new StringRequest(Request.Method.POST, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {

                        json      = new JSONObject(response);
                        userId    = json.getString("userid");
                        userType  = json.getString("usertype");
                        dbversion = json.getInt("dbversion");
                        success   = json.getInt(TAG_SUCCESS);
                        message   = json.getString(TAG_MESSAGE);

                        if (pDialog != null && pDialog.isShowing()) {
                            pDialog.dismiss();
                        }

                        enviadoComSucesso();


                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    error.printStackTrace();
                    if (pDialog != null && pDialog.isShowing()) {
                        pDialog.dismiss();
                    }
                    userMsg("Não foi possível fazer conexão, por favor tenta novamente.");
                }
            }
    ) {
        @Override
        protected Map<String, String> getParams()
        {
            String usuario  = LoginActivity.this.userTemp;
            String password = LoginActivity.this.passTemp;

            Map<String, String> param = new HashMap<>();

            //ENVIO DOS DADOS DE AVALIAÇÕES
            param.put("usuario", usuario);
            param.put("password", password);


            return param;
        }
    };
    // Adding JsonObject request to request queue
    AppSingleton.getInstance(getApplicationContext()).addToRequestQueue(postRequest,REQUEST_TAG);
    postRequest.setRetryPolicy(new DefaultRetryPolicy(
            2000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
}

为什么现在显示此错误?我所有的应用程序现在都有这个错误。当我看到这个错误时,我搜索并通过 Sticky 找到了这个解决方案

该问题是由于后端禁用了 TLSv1。根据具体情况,可以有两种方法来解决这个问题。1. 在后端服务器上启用 TLSv1。2. 按照建议,更新 SSLEngine 以在移动应用上支持更高的 TLS 版本。

但我面临困难,因为不是 VOLLEY APROACH,我必须做什么?

4

1 回答 1

1

几个月前我遇到过这个问题,解决方案是从后端启用 TLSv1 协议

检查这个

SSL protocols supported by devices lower than 4.4 "TLSv1" and "SSLv3"

SSL protocols supported by devices higher than 4.4 "TLSv1", "TLSv1.1" and "TLSv1.2"

您的 Volley 代码没有问题

于 2018-02-21T17:03:33.293 回答