hi~ What reason is this? user retrofit 2.0
@FormUrlEncoded
@DELETE(USER_COLLECTION_PRODUCT)
retrofit.Call
FATAL EXCEPTION: main
java.lang.IllegalArgumentException: FormUrlEncoded can only be specified on HTTP methods with request body (e.g., @POST).
for method RequestInterface.deleteCollect
at retrofit.Utils.methodError(Utils.java:177)
at retrofit.Utils.methodError(Utils.java:167)
at retrofit.RequestFactoryParser.parseMethodAnnotations(RequestFactoryParser.java:143)
at retrofit.RequestFactoryParser.parse(RequestFactoryParser.java:59)
at retrofit.MethodHandler.create(MethodHandler.java:30)
at retrofit.Retrofit.loadMethodHandler(Retrofit.java:151)
at retrofit.Retrofit$1.invoke(Retrofit.java:132)
but
@HTTP(method = "DELETE", path = USER_COLLECTION_PRODUCT, hasBody = true)
Results caught into a "put" request
Mere user/lurker here - but my 2c on this: I'd say this was somewhat valid. Whilst specs seem to say that DELETE requests _can_ have a body, they're also very vague and hand-wavy in saying "servers how ever may not do anything with it".
So I'd say disallowing @FormUrlEncoded would be a valid (safe) place to be.
With that being said, I've come across A LOT of APIs I've tried integrating with that just insist that the Content-Type of the request be application/x-www-form-urlencoded in order to process ( badly BADLY coded servers ).
In these instances, I think it would be best documented and used in Retrofit by simply adding a @Headers("Content-Type: application/x-www-form-urlencoded") annotation to the code.
Unless, you really ARE needing to submit a body. In your example - but then I might question your API design itself, suggesting that it might not be the best approach ( unless it's an API not under your control, of which - I'd defer to the project gods for an answer ).
The @HTTP(method = "DELETE", path = USER_COLLECTION_PRODUCT, hasBody = true) annotation should work here. He seems to be saying that it gets converted into a PUT request though, which I need to write a test case to either disprove or fix.
Some information said the delete request can fit into a body some says not to be
in.https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7
However, if no detailed said cannot be put into the body
So what specifically are you asking for here?
Retrofit does not have the ability to model whether a HTTP method can optionally take a body. We either enforce the body is present or we enforce it is absent. For DELETE we enforce it to be absent since a large majority of APIs do not use a body for it. Are you asking for optional bodies? Or something else?
Most helpful comment
The
@HTTP(method = "DELETE", path = USER_COLLECTION_PRODUCT, hasBody = true)annotation should work here. He seems to be saying that it gets converted into a PUT request though, which I need to write a test case to either disprove or fix.