Click here to Skip to main content
15,880,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need help to fix this bug, i already use a delete method in volley but when i tried,
the code showing response 400, here is my code
JSONObject params = new JSONObject();
               try {
                   String id = getIntent().getStringExtra(KEY_NIK);
                   params.put("id", id);
               }
               catch (JSONException e) {
                   e.printStackTrace();
               }

               JsonObjectRequest request=new JsonObjectRequest(Request.Method.DELETE, "http://******/index", params, new Response.Listener<JSONObject>() {
                   @Override
                   public void onResponse(JSONObject response) {
                       hideDialog();
                       Toast.makeText(getApplicationContext(), "sudah di update", Toast.LENGTH_LONG).show();
                       detail_activity.this.finish();

                   }
               }, new Response.ErrorListener() {
                   @Override
                   public void onErrorResponse(VolleyError error) {
                       Toast.makeText(getApplicationContext(), "maaf ada kesalahan", Toast.LENGTH_LONG).show();

                   }
               })
               {
                   @Override
                   public Map<String, String> getHeaders() throws AuthFailureError {
                       HashMap<String, String> headers = new HashMap<String, String>();
                       String creds = String.format("%s:%s", "admin", "Databa53");
                       String auth = "Basic " + Base64.encodeToString(creds.getBytes(), Base64.DEFAULT);
                       headers.put("Authorization", auth);
                       return getHeaders();
                   }
               };
               RequestQueue requestQueue = Volley.newRequestQueue(detail_activity.this);
               requestQueue.add(request);


What I have tried:

i tried using postman but in worked but when i using android, it doesn't work
Posted
Comments
David Crow 11-Sep-21 10:39am    
400 indicates something is wrong with the request. Is the request malformed?
Komang Putra 12-Sep-21 2:37am    
no.. the parameter is right
Richard Deeming 13-Sep-21 6:06am    
Well it's clearly not.

You'll need to capture a network trace and compare the working request from Postman with the non-working request from your code to see what's different.
Member 15329613 13-Sep-21 9:07am    
If postman works and android does not then you need to compare the 2 requests and see what android is missing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900