How to send a HTTP-delete with a body in retrofit?

后端 未结 6 1251
暖寄归人
暖寄归人 2020-12-14 01:44

When I try to create a delete method:

public interface ImageService {
    @DELETE(\"api/v1/attachment\")
    Call delete(@Body DeleteMode         


        
6条回答
  •  没有蜡笔的小新
    2020-12-14 01:51

    In case you are you are using an old version that doesn't support @HTTP, you can also add another interface that implements the @RestMethod

    import java.lang.annotation.Retention;
    import java.lang.annotation.Target;
    import retrofit.http.RestMethod;
    
    import static java.lang.annotation.ElementType.METHOD;
    import static java.lang.annotation.RetentionPolicy.RUNTIME;
    
    /** Make a DELETE request to a REST path relative to base URL with body. */
    @Target(METHOD)
    @Retention(RUNTIME)
    @RestMethod(value = "DELETE", hasBody = true)
    public @interface DELETEWITHBODY {
      String value();
    }
    

    And then the usage becomes:

    public interface ImageService {
        @DELETEWITHBODY("api/v1/attachment")
        Call delete(@Body DeleteModel deleteModel);
    }
    

提交回复
热议问题