在排球库中给出com.android.volley.ServerError [英] In volley library giving com.android.volley.ServerError
本文介绍了在排球库中给出com.android.volley.ServerError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试登录我的应用程序,当我尝试使用排球库调用API时,它给出了com.android.volley.ServerError和响应代码400.
I try to login in my application, when I try to call API using volley library, it's giving com.android.volley.ServerError and response code 400.
final String username = editTextUsername.getText().toString().trim();
final String password = editTextPassword.getText().toString().trim();
final String email = editTextEmail.getText().toString().trim();
StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this,response,Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this,error.toString(),Toast.LENGTH_LONG).show();
}
}){
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put(KEY_USERNAME,username);
params.put(KEY_PASSWORD,password);`enter code here`
params.put(KEY_EMAIL, email);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
我看到了很多例子,但没有得到任何解决方案.
I saw the many examples but I did not get any solution.
推荐答案
我遇到了同样的问题.我一整天都筋疲力尽.最终,我发现了一个小错误,那就是我在参数中传递了一个空值.
I had the same issue. It drained my entire day. Finally, I Found the tiny error, which was that I was passing a null value in parameters.
检查是否在getParams()或JSON对象中将空值传递给服务器.如果是,那可能是问题所在.
Check if you are passing a null value to the server in getParams() or your JSON Object. If yes, that may be the problem.
这篇关于在排球库中给出com.android.volley.ServerError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文