使用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);
网友评论