简体   繁体   English

为什么 Volley 不在 getParams() 中发送变量?

[英]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. PHP 很好,但没有发送用户名和密码。

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.最后发现代码没有通过getParams(),所以我把它变成了一个字符串请求,并将响应字符串解析成一个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.我在网上找不到太多关于它的信息,所以 IDK 为什么这一切都不起作用,我不能认为这是一个答案,所以它更像是一个更新。

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

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