使用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);