当我尝试创建delete方法时:
public interface ImageService {
@DELETE("api/v1/attachment")
Call<BaseResponse> delete(@Body DeleteModel deleteModel);
}我得到的错误基本上可以归结为堆栈跟踪中的以下几行:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Failure delivering result
java.lang.IllegalArgumentException: Non-body HTTP method cannot contain @Body.
Caused by: java.lang.IllegalArgumentException: Non-body HTTP method cannot contain @Body.如何将主体添加到delete方法?
我已经在这里搜索过了,但发现有3个没有答案,也没有使用改装。
发布于 2017-01-13 15:36:07
一个更简单的答案。
@HTTP(method = "DELETE", path = "/api/analysis_delete", hasBody = true)
Call<Analysis_Delete_RequestResult_Api10> analysis_delete_api10(@Field("seq") String seq);这样就可以了。
发布于 2017-12-07 13:58:55
这是我的版本
@HTTP(method = "DELETE", path = "{login}", hasBody = true)
Call<ResponseBody> getData(@Path("login") String postfix, @Body Map<String, Object> options);发布于 2018-03-26 19:56:04
以下是文档的摘录,这是HTTP注释的一个文档功能。
This annotation can also used for sending DELETE with a request body:
interface Service {
@HTTP(method = "DELETE", path = "remove/", hasBody = true)
Call<ResponseBody> deleteObject(@Body RequestBody object);
}https://square.github.io/retrofit/2.x/retrofit/retrofit2/http/HTTP.html
https://stackoverflow.com/questions/41509195
复制相似问题