0

I'm passing a key-value pair in String request using post request method I'm getting error 400. The Error is:E/Volley: [1120] NetworkUtility.shouldRetryException: Unexpected response code 400 for http://11.1.1.86:9000/cef/investmentStrategies/android

RequestQueue MyRequestQueue = Volley.newRequestQueue(getContext());
                                       url5 = "http://11.1.1.86:9000/cef/investmentStrategies/android";
                                       StringRequest stringRequest5 = new StringRequest(Request.Method.POST, url5, new Response.Listener<String>() {
                                           @Override
                                           public void onResponse(String response) {
                                               System.out.println("No Error");
                                           }
                                       }, new Response.ErrorListener() {
                                           @Override
                                           public void onErrorResponse(VolleyError error) {
                                                   System.out.println("Error is here..");
                                           }
                                       }) {

                                           @Nullable
                                           @Override

                                           protected Map<String, String> getParams() {
                                               Map<String, String> MyData = new HashMap<String, String>();
                                               MyData.put("Field",id);
                                               return MyData;
                                           }
                                           @Override
                                           public Map<String, String> getHeaders() throws AuthFailureError {
                                               Map<String, String> params = new HashMap<String, String>();
                                               params.put("Content-Type", "application/json");
                                               return params;
                                           }

                                       };
                                       MyRequestQueue.add(stringRequest5);
                                   }
  • A POST request has always a body. Where do you set the body of your POST request (I only see GET parameters and headers)? For an Volley POST example see https://stackoverflow.com/a/33578202/150978 – Robert Feb 16 '23 at 10:29

0 Answers0