For some time now I ask a question related to the retofit android library that I use to create an authorization screen in my application. I have already been told and advised a lot of things, I read a lot of things on the Internet. As a result, at the moment I created a naked application for working with the retofit library which converts the entered text into the form fields in json and then after clicking on the submit button, the converted information is displayed in the textview. To work with this issue, I used my previous questions: Please help me with the Retrofit android library during authorization in the application
Explain the principles of authorization development in android
There are a lot of practical advice, after which I divided my task into several subtasks, namely, I have created (it seems to me that everything works correctly there) just the project structure for converting data to json, but the server to which I’m not sending my requests http://jsonplaceholder.typicode.com/ and most likely just used in the example to emulate queries. Here are my classes for work: 1.
import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; public class RetrofitClient { private static Retrofit retrofit = null; public static Retrofit getClient() { if (retrofit==null) { retrofit = new Retrofit.Builder() .baseUrl("http://jsonplaceholder.typicode.com/") .addConverterFactory(GsonConverterFactory.create()) .build(); } return retrofit; } } 2
import com.example.developer_4.test_log.APIService; public class ApiUtils { private ApiUtils() {} public static APIService getAPIService() { return RetrofitClient.getClient().create(APIService.class); } } 3
import com.example.developer_4.test_log.data.model.model.LoginRequest; import retrofit2.Call; import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; import retrofit2.http.POST; public interface APIService { @POST("/posts") @FormUrlEncoded //Call<ServerResponce> authUser(@Body LoginRequest body); Call<LoginRequest> savePost(@Field("login") String login, @Field("password") String password); } four.
public class LoginRequest { @SerializedName("login") @Expose private String login; @SerializedName("password") @Expose private String password; public String getLogin() { return login; } public void setLogin(String login) { this.login = login; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public String toString() { return "LoginRequest{" + "login ='" + login + '\'' + ", password =" + password + '}'; } } and now I want to send a request to the server I need, but I don’t get it, I don’t seem to have an error and the program doesn’t crash, but I still can’t understand what the problem is. server request and if anyone knows how to explain this question to me, I will be very grateful to him.