I try to send a DELETE request to my server, but I get a 400 bad request error code back. I search a lot but I can't find any solution that help. When I try it with Postman, the request works fine.
This is how the curl command from Postman looks:
curl --location --request DELETE 'https://blablabla.de' \
--header 'Content-Type: application/json' \
--data-raw '{
"deviceId":"33",
"factoryReset":"0"
}'
This is my Java code:
public void unlinkDevice(String deviceId) {
Log.d(LOG_TAG, "unlinkDevice: " + deviceId);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("deviceId", deviceId);
jsonObject.put("factoryReset", 0);
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest request = new JsonObjectRequest(Request.Method.DELETE, url, jsonObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
listener.onDeviceUnlink(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
listener.onError(error);
}
}) {
@Override
public String getBodyContentType() {
return "application/json; charset=utf-8";
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("Cookie", StartApplication.getCookie());
return headers;
}
};
queue.addToRequestQueue(request);
}
I also try it without to set the Content-Type in the header, but when I get a 415 error and I also removed the getBodyContentType() method, but this also changed nothing.
Any other ideas that can help ?