HTTP GET with request body RETROFIT

user2026760 picture user2026760 · Apr 23, 2015 · Viewed 33.5k times · Source

I am using Retrofit to make api calls in my android application. I have to submit a @Body of JSON

@GET("api/")
void getData(@Body UserPostRequestBody request)

I get error message

retrofit.RetrofitError: apiCall: Non-body HTTP method cannot contain @Body or @TypedOutput.

Have you any idea?

Answer

harshitpthk picture harshitpthk · Sep 7, 2015

To send data along with your Get Request you can do the following:

//sending data as a url parameter
@GET("/group/{id}/users")
List<User> groupList(@Path("id") int groupId);

as said in this SO answer, Server semantics for GET, however, are restricted such that a body, if any, has no semantic meaning to the request- Roy Fielding.