繁体   English   中英

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

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

我正在尝试通过将用户名和密码发送到验证帐户的代码中提到的网页,然后将我的数据库中机器的信息发回,来列出与应用程序用户相关的机器。 PHP 很好,但没有发送用户名和密码。

这是请求的代码:

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

用户名和密码已用于登录并作为此活动的附加信息发送。

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

暂无
暂无

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

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