排球-BasicNetwork.performRequest:意外的响应代码400 POST

时间:2019-03-15 20:02:10

标签: java android json post android-volley

邮递员头

[{"key":"Content-Type","name":"Content-Type","type":"text","value":"application/json"},{"key":"token","type":"text","value":"ffBJpLW55i"}]

即使我将令牌值而不是令牌字符串也不能使用

                    headers.put("Content-Type", "application/json");
                    headers.put("token", "ffBJpLW55i");

2019-03-15 21:51:15.384 20577-20620 / com.sleepyhitman.ab4_internship_2019try2 E / Volley:[816] BasicNetwork.performRequest:https://tralalala.com/api-spot-get-all的意外响应代码400

    private void loadRecyclerViewData(final String token){
            RequestQueue requestQueue = Volley.newRequestQueue(this);
            StringRequest listRequest = new StringRequest(Request.Method.POST,URL_DATA+"api-spot-get-all",
                    new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject jsonObject = new JSONObject(response);
                        JSONArray array = jsonObject.getJSONArray("result");
                        for (int i =0; i<array.length(); i++) {
                            JSONObject o = array.getJSONObject(i);
                            ListItem list = new ListItem(
                                    o.getString("id"),
                                    o.getString("name"),
                                    o.getString("country"),
                                    o.getString("whenToGo"),
                                    o.getBoolean("isFavorite")
                            );
                            listItems.add(list);
                        }
                        ListItemAdapter listItemAdapter = new ListItemAdapter(getApplicationContext(), listItems);
                        recyclerView.setAdapter(listItemAdapter);

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
 //
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }){

                @Override

                public Map<String, String> getHeaders() throws AuthFailureError {
                    HashMap<String, String> headers = new HashMap<String, String>();
                    headers.put("Content-Type", "application/json");
                    headers.put("token", token);
                    return headers;
                }

                protected Map<String, String> getParams() {
                    Map<String, String> params = new HashMap<String, String>();
                    params.put("country", "");
                    params.put("windProbability", "");
                    return params;
                }
};



    requestQueue.add(listRequest);


}

1 个答案:

答案 0 :(得分:0)

这部分是排球请求的错误部分,

URL_DATA+"api-spot-get-all"  

在使用StringRequest时,应该有一个字符串格式的URL。