@DELETE method is not supporting(Non-body HTTP method cannot contain @Body or @TypedOutput.)

JavaRetrofitRx Java

Java Problem Overview


@DELETE("/job/deletejob")
 Observable<JobDeleteResponseModel> jobDelete( @Body JobDeleteRequestModel model);

am getting this error:

> Non-body HTTP method cannot contain @Body or @TypedOutput

Java Solutions


Solution 1 - Java

I've used this official workaround recently:

@HTTP(method = "DELETE", path = "/job/deletejob", hasBody = true)
Observable<JobDeleteResponseModel> jobDelete(@Body JobDeleteRequestModel model);

Solution 2 - Java

try this it's work

@HTTP(method = "DELETE", path = "api/v3/delete", hasBody = true)
Call<ResponseBody> RESPONSE_BODY_CALL(@Header("Authorization") String authorization, @Body HashMap<String, List> stringListHashMap);

or check https://github.com/square/retrofit/issues/974

Solution 3 - Java

You need to specify parameters
method, path, hasBody

Kotlin way

@HTTP(method = "DELETE", path = "event/eventRemovePicture", hasBody = true)
fun callDeleteImage(
    @Body body: RequestBody
): Call<RemoveEventPictureResponse>

Solution 4 - Java

I had similar error.

In my case I was using @GET in Interface but then I corrected it to @POST method and it worked.

Solution 5 - Java

Kotlin Code :

path is not required if your first argument to interface method is a url annotated with @Url Example :

@HTTP(method = "DELETE", hasBody = true)
fun deleteStudentFromDatabase(
    @Url url: String,
    @Body payload: StudentModel
 ): Observable<Any>

If first argument to interface method is not a url then use this

    @HTTP(method = "DELETE", path = "{urlPath}", hasBody = true)
    fun deleteStudentFromDatabase(
        @Body payload: StudentModel,
        @Path("urlPath") url: String
     ): Observable<Any>

Solution 6 - Java

Change

@DELETE("/job/deletejob")
Observable<JobDeleteResponseModel> jobDelete( @Body JobDeleteRequestModel model);

to

@HTTP(method = "DELETE", path = "/job/deletejob", hasBody = true)
Observable<JobDeleteResponseModel> jobDelete( @Body JobDeleteRequestModel model);

The difference is in

@DELETE("/job/deletejob") // For DELETE without body
@HTTP(method = "DELETE", path = "/job/deletejob", hasBody = true) // For DELETE with body

Solution 7 - Java

@HTTP(method = "DELETE", path = "{urlPath}", hasBody = true)

Also this is working fine. It happens because the request contains a body but we have not defined that yet.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsandyView Question on Stackoverflow
Solution 1 - JavaAndroidExView Answer on Stackoverflow
Solution 2 - JavaShiv KumarView Answer on Stackoverflow
Solution 3 - JavaAditya PatilView Answer on Stackoverflow
Solution 4 - JavaMakarandView Answer on Stackoverflow
Solution 5 - JavaRamakrishna JoshiView Answer on Stackoverflow
Solution 6 - JavaJunior CarrilloView Answer on Stackoverflow
Solution 7 - JavaYogesh BansalView Answer on Stackoverflow