我正在研究一个项目,并且我不断抛出异常" com.android.volley.AuthFailureError"我浪费了我2天的时间。如果有最好的解决方案的人做评论。 pramaters是 "电子邮件:h4@gmail.com 名称:h3的 纬度:123456 LNG:123456 角色:客户 地址:13246546543213 lat_lng:012354 密码:123456 ID:123456 邮政编码:123456"
StringRequest stringRequest = new StringRequest(Request.Method.POST, "http://webmarke8.com/gincart/api/login", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if(response.trim().equals("success")){
Toast.makeText(LoginActivity.this, "Success", Toast.LENGTH_SHORT).show();
finish();
progress.hide();
}else{
Toast.makeText(LoginActivity.this,response,Toast.LENGTH_LONG).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progress.dismiss();
if (error instanceof TimeoutError || error instanceof NoConnectionError) {
Toast.makeText(getApplicationContext(), "Communication Error!", Toast.LENGTH_SHORT).show();
} else if (error instanceof AuthFailureError) {
Toast.makeText(getApplicationContext(), "Authentication Error!", Toast.LENGTH_SHORT).show();
} else if (error instanceof ServerError) {
Toast.makeText(getApplicationContext(), "Server Side Error!", Toast.LENGTH_SHORT).show();
} else if (error instanceof NetworkError) {
Toast.makeText(getApplicationContext(), "Network Error!", Toast.LENGTH_SHORT).show();
} else if (error instanceof ParseError) {
Toast.makeText(getApplicationContext(), "Parse Error!", Toast.LENGTH_SHORT).show();
}
Toast.makeText(LoginActivity.this,error.toString(),Toast.LENGTH_LONG ).show();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> map = new HashMap<String,String>();
map.put("email","muhammadaqeelprivate@gmail.com");
map.put("password","123456789");
return map;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/x-www-form-urlencoded");
return headers;
}
@Override
public String getBodyContentType() {
// TODO Auto-generated method stub
return "application/x-www-form-urlencoded; charset=UTF-8";
}
};
stringRequest.setRetryPolicy(new DefaultRetryPolicy(5000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}