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

问题描述 投票:0回答:1

邮差标题

[{"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);


}
java android json post android-volley
1个回答
0
投票

这部分是你的截击请求的错误部分,

URL_DATA+"api-spot-get-all"  

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

© www.soinside.com 2019 - 2024. All rights reserved.