Answer the question
In order to leave comments, you need to log in
How to get a response from Retrofit?
I am making a GET request:
public interface CheckUserInDBRequest {
@GET("api/checkUserInDB.php")
Call<ResponseBody> searchForUser(
@Query("login") String login,
@Query("pass") String pass
);
}
Retrofit.Builder builder = new Retrofit.Builder().baseUrl("https://kurusa.zhecky.net/").addConverterFactory(GsonConverterFactory.create());
Retrofit retrofit = builder.build();
CheckUserInDBRequest client = retrofit.create(CheckUserInDBRequest.class);
Call<ResponseBody> call = client.searchForUser (
UserLogin.getText().toString(),
UserPass.getText().toString()
);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
Toast.makeText(MainActivity.this, response.body().toString(), Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
Toast.makeText(MainActivity.this, "no ", Toast.LENGTH_SHORT).show();
}
});
Answer the question
In order to leave comments, you need to log in
Well, with the help of ConverterFacetory, it should immediately generate an object from JSON. for example if object {result:true} -
UserInDatabaseStatus{
private boolean result;
public boolean getResult(){
return result;
}
public void setResult(boolean result){
this.result = result
}
@GET("api/checkUserInDB.php")
Call<UserInDatabaseStatus> searchForUser(
@Query("login") String login,
@Query("pass") String pass
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question