简体   繁体   English

Volley POST StringRequest 没有给出任何响应

[英]Volley POST StringRequest not giving any response

I've given permissions for Internet access to my application and the URL I'm using is right (I can do POST requests through postman correctly).我已授予对我的应用程序的 Internet 访问权限,并且我使用的 URL 是正确的(我可以通过 postman 正确执行 POST 请求)。 But in my application the requests fail:但在我的应用程序中,请求失败:

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);
        }
    });

My emulator does not give me any responses, just stays on login activity (which is the main one).我的模拟器没有给我任何回应,只是停留在登录活动(这是主要活动)。

Just rebuild the app, honestly it was that now it works.只需重建应用程序,老实说,现在它可以工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM