改造2删除方法任务失败

时间:2017-08-16 14:34:02

标签: android retrofit retrofit2

我在我的API界面中获得了这个方法

@DELETE("/posts/{id}") 
Call<Void> deletePost(@Path("id") int id);

但我打电话的方法面临失败:

mAPIService.deletePost(id ).enqueue(new Callback<Void>() {
    @Override
    public void onResponse(Call<Void> call, Response<Void> response) {

        if(response.isSuccessful()) {
            showResponse(response.body().toString());
            Log.i("TAG", "post deleted to API." + response.body().toString());
        }
    }

    @Override
    public void onFailure(Call<Void> call, Throwable t) {
        Log.e("TAG", "Unable to submit post to API.");
    }
});

1 个答案:

答案 0 :(得分:0)

使用Call<ResponseBody>,而不是Call<Void>