2

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?

Community
  • 1
  • 1
Anton
  • 507
  • 3
  • 12
  • Duplicate of http://stackoverflow.com/questions/17580062/how-can-i-configure-squares-retrofit-client-to-handle-a-request-with-a-variable – gnuf Oct 30 '13 at 16:37

1 Answers1

4

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

gnuf
  • 2,722
  • 1
  • 25
  • 32