@DELETE方法不支持(非body HTTP方法不能包含@Body或@TypedOutput。)

时间:2016-06-21 10:53:30

标签: retrofit rx-java

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

我收到此错误:

  

非正文HTTP方法不能包含@Body或@TypedOutput

任何人都可以帮助我从这里出来吗?

6 个答案:

答案 0 :(得分:138)

我最近使用过这个官方解决方法:

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

答案 1 :(得分:4)

您需要指定参数
方法,路径,hasBody

科特林方式

least_squares

答案 2 :(得分:3)

尝试这项工作

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

或检查 https://github.com/square/retrofit/issues/974

答案 3 :(得分:2)

我有类似的错误。

在我的情况下,我在Interface中使用@GET,但后来将其更正为@POST方法,并且可以正常工作。

答案 4 :(得分:0)

科特琳代码:

如果接口方法的第一个参数是@Url注释的URL,则不需要

path 例子:

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

如果接口方法的第一个参数不是url,则使用此

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

答案 5 :(得分:0)

改变

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

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

区别在于

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