Question

I'm using Square's Retrofit library. I need to implement request with variable number of parameters. I've found suggestion (link) and I try this:

I change

@GET("someURL")
void method(
        @Query("firstParameter") int firstValue,
        @Query("secondParameter") String secondValue,
        Callback<Response> cb
);

to

@POST("someURL")
void method(
        @Body Map<String, Object> parameters,
        Callback<Response> cb
);

and use follow:

final HashMap<String, Object> param = new HashMap<String, Object>();
param.put("firstParameter", firstValue);
param.put("secondParameter", secondValue);

The first way works great, but the second one doesn't work. What's wrong?

Was it helpful?

Solution

Well, you're switching from a GET to a POST, so instead of passing query parameters, you are passing values in the body.

Retrofit doesn't currently support variable arguments in GET requests. A ticket to add support for this is tracked in this GitHub issue: https://github.com/square/retrofit/issues/293

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top