fvthree
fvthree

Reputation: 51

Retrofit POST with multiple query params

I would like to do a POST Command.

This is my endpoint: http://180.150.134.136:18095/WSCoreAPI/send/receive/tester?method=LOGN&data=(urlencodeddata)

my question is how will i structure the endpoint in my retrofit

i did something like this:

@POST("WSCoreAPI/send/receive/tester")
Call<LoginResponse> tester(
        @QueryMap Map<String, String> data);

but it is not working

as well as this:

@POST("WSCoreAPI/send/receive/tester")
Call<LoginResponse> tester(
        @Query("method") String method,
        @Query("data") String data);

Upvotes: 1

Views: 3515

Answers (3)

fvthree
fvthree

Reputation: 51

Okay so I got it working.

I used either two of the above solutions.

what i did was i removed the url encoding of the "data" query params and used this:

@FormUrlEncoded
@POST("WSCoreAPI/send/receive/tester")
Call<LoginResponse> tester(@Field("method") String method,
                           @Field("data") String data);

removing the url encoding fix the problem because retrofit will automatically encode the fields annotated with @Field

Upvotes: -1

khaleel_jageer
khaleel_jageer

Reputation: 1512

try this

@FormUrlEncoded
@POST("WSCoreAPI/send/receive/tester")
Call<LoginResponse> tester(@FieldMap Map<String, String> parameters);

Upvotes: 1

Andrej Jurkin
Andrej Jurkin

Reputation: 2266

Use @Field and @FormUrlEncoded for url encoded fields

@FormUrlEncoded
@POST("WSCoreAPI/send/receive/tester")
Call<LoginResponse> tester(@Field("method") String method,
                           @Field("data") String data);

Upvotes: 1

Related Questions