It is necessary to create a POST request with sending a login, password and getting a token, I was recommended to retrofit, since it cannot be done using standard methods. But I do not understand how the request is created in it (the documentation looked), for example
public interface API { @POST("/v1/registration") Response registerUser(); }
But at least I don’t understand where the link to the site is and where the request parameters are set. Here I see a request to register a user, but where is all the data? Does he take them from the method?
UPD:
public interface API { @POST("/v1/registration") Response registerUser(@Body RegistrationBody registrationBody); Call<RegistrationResponse> registerUser(); } public class RegistrationBody{ public String login; public String password; } public class RegistrationResponse { public String token; } Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://myserver1.com") .build(); API api = retrofit.create(API.class); @POST("/v1/registration") Call<RegistrationResponse> registerUser(@Body RegistrationBody registrationBody) { return null; } Call<RegistrationResponse> call = api.registerUser(); call.enqueue(new Callback<RegistrationResponse() { @Override public void onResponse(Response<RegistrationResponse> response) { if (response.isSuccess()) { // tasks available } else { // error response, no access to resource? } }
there are errors starting with call.enqueue
Call<RegistrationResponse> registerUser()
method must be exactly the same as the normal one, except for the return parameter. - temq