How to get a response from the server that the user exists in the database?

I want to implement the registration of the application. There are RegisterActivity and when the user enters the data, they are sent to my server, is processed by PHP and stored in the database. I created a Server class that sends my data with POST request (using the OkHTTP library) and I wonder if PHP answer, let's say that this user is already in the database, how do I return the user response? How to get the answer what is PHP? Maybe through the response object? I'm in the Top until it floats
Class code:
public class Server {

 public static final String address = "address of server here";

 public static void register(String username, String password) {
 OkHttpClient client = new OkHttpClient();
 FormBody.FormBuilder Builder = new FormBody.Builder();
 formBuilder.add("username", username);
 formBuilder.add("password", password);
 RequestBody body = formBuilder.build();
 Request request = new Request.Builder().url(Server.address).post(body).build();
 try {
 Response response = client.newCall(request).execute();
 } catch (IOException e) {
e.printStackTrace();
}
}
}
June 14th 19 at 18:52
1 answer
June 14th 19 at 18:54
Solution
two ways
through the response.body(). something more specific
and using the response code of the server response.code()
keep in mind that isSuccessful() are the codes 200-299
it is also desirable to check the answers isSuccessful(). You never know what.
for thought www.restapitutorial.ru/httpstatuscodes.html
And if we assume the errors different?
Option 1: the server will verify that whether there is a login
Option 2: another type of error associated with the login (an invalid character)
How to give the user for example that the problem is that trabbi with the fact that such a username exists, and not with something else? - eloisa32 commented on June 14th 19 at 18:57
well make a response in body()
for example Yandex translator does.

{"code":401,"message":"API key is invalid"} - Eulah.Hamill commented on June 14th 19 at 19:00
https://tech.yandex.ru/translate/doc/dg/reference/...
{"code":401,"message":"API key is invalid"} - Eulah.Hamill commented on June 14th 19 at 19:03

Find more questions by tags Android