I'm trying to make an asynchronous POST and DELETE which is form url encoded using Retrofit in Android 4.4
Here is my client -
@FormUrlEncoded
@POST(INetwork.API_BASE_PREFIX + "/memberships.json")
void join(@Field("id") String id, Callback<?> cb);
@FormUrlEncoded
@DELETE(INetwork.API_BASE_PREFIX + "/memberships.json")
void leave(@Field("id") String id, Callback<?> cb);
And this is the exception -
java.lang.IllegalArgumentException: IRepositoryClient.leave: FormUrlEncoded can only be specified on HTTP methods with request body (e.g., @POST).
at retrofit.RestMethodInfo.methodError(RestMethodInfo.java:118)
at retrofit.RestMethodInfo.parseMethodAnnotations(RestMethodInfo.java:191)
at retrofit.RestMethodInfo.init(RestMethodInfo.java:128)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:329)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:264)
at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:315)
at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:841)
I looked through the source and it basically if the method doesn't have a body and the request is formurlencoded, this exception is thrown. Also I noticed that all example of FormUrlEncoded work fine when it is not asynchronous, i.e. I have a return type of some sort and no callback - sorry I'm a little lost
Should I send an empty body? Am I required to send one and won't the @Field parameters suffice?
Using Retrofit 1.5.0
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…