我正在使用android volley向我的API链接发送请求。当我在邮递员中使用相同的链接并传递参数时,它会给我成功的响应。但是,当我尝试在邮递员中运行它时,出现了错误的请求错误,意外的响应代码400。
我的android代码如下:
StringRequest stringRequest = new StringRequest(Request.Method.POST, URLs.URL_AUTHENTICATE, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("Volley Result", "" + response); //the response contains the result from the server, a json string or any other object returned by your server
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace(); //log the error resulting from the request for diagnosis/debugging
dialog.dismiss();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> postMap = new HashMap<>();
postMap.put("username", username);
postMap.put("password", password);
postMap.put("Content-Type", "application/x-www-form-urlencoded");
return postMap;
}
};
FcmVolley.getInstance(this).addToRequestQueue(stringRequest);
}
我该如何解决?