简体   繁体   中英

Error Android Volley Unexpected response code 400

i am using volley for a get data function but i get unexpected response code 400 for http. Below i have pasted my code

      RequestQueue queue = Volley.newRequestQueue(getActivity());
            StringRequest sr = new StringRequest(Request.Method.PUT,URL, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.e("loi", "" + response);
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("loi", "" + error);
                }
            }){
                @Override
                protected Map<String,String> getParams(){
                    Map<String,String> params = new HashMap<String, String>();
                    int size = SupportData.vtvlist.get(stt).getmPostArrayList().size();
                    for (int i = 0; i < size; i++) {
                        name = SupportData.vtvlist.get(stt).getmPostArrayList().get(i).getNamepost().toString();
                        value = SupportData.vtvlist.get(stt).getmPostArrayList().get(i).getValue().toString();
                        params.put(""+name,value);
                    }

                    return params;
                }

                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    Map<String,String> params = new HashMap<String, String>();
                    params.put("Content-Type","application/x-www-form-urlencoded");
                    return params;
                }
            };
            queue.add(sr);

Is there anyone who can tell me where I am doing wrong in my code? Any help is appreciable.

尝试将Request.Method.PUT更改为Request.Method.POST因为您尝试使用StringRequest获取数据。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM