@DELETE("/job/deletejob")
Observable<JobDeleteResponseModel> jobDelete( @Body JobDeleteRequestModel model);
我遇到了这个错误:
非请求体HTTP方法不能包含@Body或@TypedOutput
@DELETE("/job/deletejob")
Observable<JobDeleteResponseModel> jobDelete( @Body JobDeleteRequestModel model);
我遇到了这个错误:
非请求体HTTP方法不能包含@Body或@TypedOutput
我最近使用了这个官方的解决方法:
@HTTP(method = "DELETE", path = "/job/deletejob", hasBody = true)
Observable<JobDeleteResponseModel> jobDelete(@Body JobDeleteRequestModel model);
path
不是必需的。更多细节请参见此处:stackoverflow.com/a/62920127/8956093 - Ramakrishna Joshi您需要指定参数
方法、路径、是否有请求体
Kotlin方式
@HTTP(method = "DELETE", path = "event/eventRemovePicture", hasBody = true)
fun callDeleteImage(
@Body body: RequestBody
): Call<RemoveEventPictureResponse>
我遇到了类似的错误。
我的情况是在接口中使用了 @GET
,但我将其更正为 @POST
方法后,问题得以解决。
@Body
动词进行 GET 请求是没有意义的。 - dipakbari4@HTTP(method = "DELETE", path = "api/v3/delete", hasBody = true)
Call<ResponseBody> RESPONSE_BODY_CALL(@Header("Authorization") String authorization, @Body HashMap<String, List> stringListHashMap);
更改
@DELETE("/job/deletejob")
Observable<JobDeleteResponseModel> jobDelete( @Body JobDeleteRequestModel model);
to
@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
Kotlin 代码:
如果你的接口方法的第一个参数带有 @Url 注解,则不需要指定 path
。例如:
@HTTP(method = "DELETE", hasBody = true)
fun deleteStudentFromDatabase(
@Url url: String,
@Body payload: StudentModel
): Observable<Any>
@HTTP(method = "DELETE", path = "{urlPath}", hasBody = true)
fun deleteStudentFromDatabase(
@Body payload: StudentModel,
@Path("urlPath") url: String
): Observable<Any>
@HTTP(method = "DELETE", path = "{urlPath}", hasBody = true)
这也可以正常工作。这是因为请求包含一个主体,但我们尚未定义它。
Retrofit 2,我已经将以下代码从这里更改
@DELETE("example/user/{id}/list")
suspend fun deleteUserList(@Path(value = "id", encoded = false)key: Int, @Body request: DeleteUserListRequest): Response<BaseResponse>
到
@HTTP(method = "DELETE", path = "example/user/{id}/list",hasBody = true)
suspend fun deleteUserList(@Path(value = "id", encoded = false)key: Int, @Body request: DeleteUserListRequest): Response<BaseResponse>
上述代码对我来说是有效的
Kotlin中的挂起函数。 默认情况下,DELETE方法不支持请求体。您应该显式启用它。
@HTTP(
method = "DELETE",
path = "path/to/api/{someRoute}/{id}",
hasBody = true
)
suspend fun delete(
@Path("someRoute") someRoute: String,
@Path("id") id: String,
@Body body: SomeBodyModel,
): Response<Unit>
使用方法如下
suspend fun delete(model: SomeBodyModel) {
val response = api.delete(model)
if (!response.isSuccessful) throw HttpException(response)
}