Search code examples
androidapiretrofit2

How to call DELETE method in retrofit 2 with params


I am calling delete api using retrofit2 it is working in postman properly but giving error in application as below

Response{protocol=http/1.0, code=405, message=METHOD NOT ALLOWED, url=http://192.168...

here is my base url

public static final String BASE_URL = "http://192.168.1.127:3222/";

@DELETE("student/{firstname}/{lastname}")
Call<ResponseBody> deleteStudent(@Path("firstname") String firstname, @Path("lastname") String lastname);

and java file i'm calling it like

Call<ResponseBody> call = interfaces.deleteStudent(FirstName,LastName);```

Postman screenshot here


Solution

  • Updated thanks for your referance @GovindPrajapati i have to make little changes add @Field and it is working for me.

    @FormUrlEncoded
        @HTTP(method = "DELETE", path = "student",hasBody = true)
        Call<ResponseBody> deleteStudent(@Field("firstname") String firstname, @Field("lastname") String lastname);