Retrofit @Delete with body,Non-body HTTP method cannot contain @Body

使用retrofit進行delete請求時,發現其並不支持向服務器傳body,會報這個異常java.lang.IllegalArgumentException:Non-body HTTP method cannot contain @Body ,之前我的delete請求是這麼寫的

@DELETE("/my/remove") Call<Void> remove (@Body HashMap<String,String> content);

結果就出現了Non-body HTTP method cannot contain @Body這錯誤,然後去github在retrofit Issues 鏈接 去找了下答案, 發現需要自定義註解,如需向服務器傳body可以這麼寫

@HTTP(method = "DELETE",path = "/my/remove",hasBody = true) Call<Void> remove (@Body HashMap<String,String> content);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章