How to pass string in 'Body' Parameter of Retrofit 2 in android

后端 未结 2 996
死守一世寂寞
死守一世寂寞 2020-12-31 06:51
@POST(\"api/login\")
Call loginUser(@Body String user);

Here the string is actually a JSONstring i.e.

{\"email\         


        
相关标签:
2条回答
  • 2020-12-31 07:08

    Convert your data in object

    public class Credentials
    {
        public String email;
        public String password;
    }
    

    Set the data to object

    Credentials loginCredentials = new Credentials();
    loginCredentials.email = "test@gmail.com";
    loginCredentials.password = "password";
    

    Call your api

    @POST("api/login")
    Call<ApiResponse> loginUser(@Body Credentials credentials);
    
    0 讨论(0)
  • 2020-12-31 07:19
    @POST("api/login")
    Call<ApiResponse> loginUser(@Body HashMap<String, String> user);
    

    We can use Hasmap here like this.

    0 讨论(0)
提交回复
热议问题