简体   繁体   中英

Android Retrofit 2 make POST request multiple params (without FormUrlEncoded)

I would like to make a POST request call with multiple params instead of one @Body param. I'm not using @FormUrlEncoded annotation on this one and I don't want to. I'm using Retrofit 2.0.

Currently, the call is made this way :

@POST("user/register")
Call<APIResponse> register(@Body RequestRegisterParams params);

with RequestRegisterParams being :

public class RequestRegisterParams {
    public String username;
    public String email;
    public String password;
}

I would like to be able to do this (with proper annotations of course) :

@POST("user/register")
Call<APIResponse> register(String username, String email, String password);

My goal is to get rid of the data model class. Is there a way to do this or a POST request without @FormUrlEncoded must have only one @Body param ? I know it can only be one @Body param but maybe with other annotations ?

Thanks in advance !

@FormUrlEncoded
@POST("user/register")
Call<APIResponse> updateUser(@Field("username") String username, @Field("email") String email, @Field("password") String password);

@Field is Named pair for a form-encoded request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM