简体   繁体   中英

why isn't Volley sending the variables in getParams()?

I'm Trying to list machines which are related to the user of the application by sending the username and password to the webpage mentioned in the code verifying the account and then sending back the information of the machines in my database. the PHP well but the username and password are not being sent.

here is the code for the request:

private void getServerResponse(String username,String password) throws IOException {
        String urlS = "http://10.0.2.2/send/sendmachines.php";
        RequestQueue RQ= Volley.newRequestQueue(this);
        JsonArrayRequest array_request = new JsonArrayRequest(Request.Method.POST, urlS, null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                TextView proof =findViewById(R.id.proof);
                for(int i=0; i<response.length(); i++){
                    try {
                        proof.setText(response.getJSONObject(0).getString("machine_id"));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                TextView proof =findViewById(R.id.proof);
                proof.setText(error.getMessage());

            }
        }){
            protected Map<String,String> getParams(){
                Map<String,String > params = new HashMap<>();
                params.put("username",username);
                params.put("password",password);
                return params;
            }
        };
        RQ.add(array_request);
    }

the username and password were already used to log in and sent as extras to this activity.

in the end it turned out that the code isn't passing through the getParams() so i turned it to a string request and parsed the response string into a jsonArray. i couldn't find much information about it online so IDK why all this isn't working and i cant consider this an answer so it's more of an update.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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