Android Volley给出错误400但在邮递员中工作

时间:2019-06-13 19:00:07

标签: java android

我正在使用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);
}

我该如何解决?

0 个答案:

没有答案