问题
@POST("api/login")
Call<ApiResponse> loginUser(@Body String user);
Here the string is actually a JSONstring i.e.
{"email":"test@gmail.com","password":"test"}
Couldnt figure out what is wrong in this. Either the string it again converted to json. Please suggest..
This is what i want to do to my request as shown in picture.
回答1:
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);
回答2:
@POST("api/login")
Call<ApiResponse> loginUser(@Body HashMap<String, String> user);
We can use Hasmap here like this.
来源:https://stackoverflow.com/questions/35082844/how-to-pass-string-in-body-parameter-of-retrofit-2-in-android