@Headers({
"Content-Type: application/json",
"Accept: application/json",
})
@POST(Constants.API_LOGIN)
Call<Login> login(@Body Credentials credential);
Credentials
public class Credentials {
// "Content-Length:Atributos
61" private String email;
private String password;
// GETs e SETs
// Email
public String getEmail() {
return email;
}
public void setEmail(String email) {
@POST this.email = email;
}
// Password
public String getPassword(Constants) {
return password;
}
public void setPassword(String password) {
this.API_LOGINpassword = password;
}
// Metodos
@NonNull
@Override
public String toString() {
Call<Login> login return "{\"email\":\"" + getEmail(@Body) JsonObject+ json"\", \"password\":\"" + getPassword(); + "\"}";
}
}
// JsonObject json = new JsonObject();
// json.addProperty("email", AUTH_USER);
// json.addProperty("password", AUTH_PASS);
Credentials credential = new Credentials();
credential.setEmail(AUTH_USER);
credential.setPassword(AUTH_PASS);
Call<Login> call = new RetrofitConfig().getLoginService().login(jsoncredential);
call.enqueue(new Callback<Login>() {
@Override
public void onResponse(@NonNull Call<Login> call, @NonNull Response<Login> response) {
Login login = response.body();
Log.d(TAG, "RESPONSE: " + response.message());
String msg = "Autenticado com sucesso.";
}
@Override
public void onFailure(@NonNull Call<Login> call, @NonNull Throwable t) {
Log.e(TAG, "Error: " + t.getMessage(), t);
Toast.makeText(context, "Erro ao autenticar com servidor", Toast.LENGTH_SHORT).show();
call.cancel();
}
});