簡體   English   中英

Volley POST StringRequest 沒有給出任何響應

[英]Volley POST StringRequest not giving any response

我已授予對我的應用程序的 Internet 訪問權限,並且我使用的 URL 是正確的(我可以通過 postman 正確執行 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);
        }
    });

我的模擬器沒有給我任何回應,只是停留在登錄活動(這是主要活動)。

只需重建應用程序,老實說,現在它可以工作了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM