【发布时间】:2021-08-22 01:10:54
【问题描述】:
我正在尝试列出与应用程序用户相关的机器,方法是将用户名和密码发送到验证帐户的代码中提到的网页,然后发回我数据库中机器的信息。 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);
}
用户名和密码已用于登录并作为附加信息发送到此活动。
【问题讨论】:
-
你怎么知道用户名和密码没有被发送?很确定这是您应该用来发送参数的方式...也许您的变量
username和password为空? -
@AlbertoSinigaglia 我用 Toast 测试了它们。
-
请使用调试器并“认真”检查发送到服务器的内容
标签: java php android mysql android-studio