【问题标题】:Volley POST StringRequest not giving any responseVolley POST StringRequest 没有给出任何响应
【发布时间】:2022-01-04 21:55:49
【问题描述】:

我已授予对我的应用程序的 Internet 访问权限,并且我使用的 URL 是正确的(我可以通过邮递员正确执行 POST 请求)。但在我的应用程序中,请求失败:

button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String email = Email.getText().toString();
            final String password = Password.getText().toString();


            StringRequest stringRequest = new StringRequest(Request.Method.POST, server_url, new Response.Listener<String>() {

                @Override
                public void onResponse(String response) {
                    if (response.equalsIgnoreCase("exitoso")) {

                        Intent intent = new Intent(MainActivity.this, Home.class);
                        startActivity(intent);
                        finish();
                    } else {
                        Toast.makeText(MainActivity.this, "Todo mal", Toast.LENGTH_SHORT).show();
                    }

                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(MainActivity.this, "Hubo un error", Toast.LENGTH_SHORT).show();
                    error.printStackTrace();
                }
            }) {
                @Override
                protected Map<String, String> getParams() {
                    Map<String, String> Params = new HashMap<String, String>();
                    Params.put("email", email);
                    Params.put("password", password);
                    return Params;
                }

                @Override
                public Map<String, String> getHeaders() {
                    HashMap<String, String> headers = new HashMap<>();
                    headers.put("Content-Type", "application/x-www-form-urlencoded;  charset=\"UTF-8");
                    return headers;
                }
            };

            RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);

            requestQueue.add(stringRequest);
        }
    });

我的模拟器没有给我任何响应,只是停留在登录活动(这是主要活动)。

【问题讨论】:

标签: java android http android-volley


【解决方案1】:

只需重新构建应用程序,老实说,现在它可以工作了。

【讨论】:

  • 我知道这是一个自我回答,但请不要称呼别人的名字。我们在这里有一个code of conduct。对自己好一点:-)。
猜你喜欢
  • 2016-06-22
  • 1970-01-01
  • 2017-09-12
  • 1970-01-01
  • 1970-01-01
  • 2016-05-04
  • 1970-01-01
  • 2018-12-21
  • 2012-06-04
相关资源
最近更新 更多