Volley android TimeoutError

问题描述 投票:0回答:1
 else {
            ejecutarServicio("http://192.168.43.1:80/Proyecto/insertar.php");
        }
    }


    private void ejecutarServicio(String URL) {
        StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Toast.makeText(getApplicationContext(), "Operacion exitosa", Toast.LENGTH_SHORT).show();
                edtNombre.setText("");
                edtEmail.setText("");
                edtDomicilio.setText("");
                edtColonia.setText("");
                edtTipoLicencia.setText("");
                edtNumLicencia.setText("");
                edtEstado.setText("");
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_SHORT).show();
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> parametros = new HashMap<String, String>();
                parametros.put("nombre", edtNombre.getText().toString());
                parametros.put("email", edtEmail.getText().toString());
                parametros.put("domicilio", edtDomicilio.getText().toString());
                parametros.put("colonia", edtColonia.getText().toString());
                parametros.put("tipo de licencia", edtTipoLicencia.getText().toString());
                parametros.put("numero de licencia", edtNumLicencia.getText().toString());
                parametros.put("estado", edtEstado.getText().toString());
                return parametros;
            }
        };
        RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
        requestQueue.add(stringRequest);
    }

我使用此代码创建了带有凌空库的Web服务,但是我只收到一条消息,指出"com.android.volley.TimeoutError",但我不知道它是否用于HTTP协议或我所缺少的其他内容;有人可以帮助我吗?

java android android-volley
1个回答
0
投票

如果超时是实际问题,则可以使用set retry策略。通过将超时设置为0,它将无限期地等待响应。或者,您可以手动设置超时(以毫秒为单位,而不是0)。

例如1:

requestQueue.setRetryPolicy(new DefaultRetryPolicy(0,
                        DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

例如2:

requestQueue.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS,
                        DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
© www.soinside.com 2019 - 2024. All rights reserved.