I'm using Retrofit library for Android.
I'm trying to connect server, sending post request and well everything, But when i'm trying to get responce.body, i get the following answer :
2020-07-04 21:37:45.931 18419-18419/com.androidapplications.mymetroword D/otvet: com.androidapplications.mymetroword.Posts@22bd74
My Pojo
public class Posts {
@SerializedName("email")
@Expose
private String email;
@SerializedName("password")
@Expose
private String password;
//getters and constructor }
My Interface
public interface ApiServices {
@FormUrlEncoded
@POST("authuser")
Call<Posts> createPost(
@Field("email") String email,
@Field("password") String password
);
}
My MainActivity
public class MainActivity extends AppCompatActivity {
EditText email_add;
Button btn_sign_in;
EditText password;
SharedPreferences sharedPreferences;
public static final String BASE_URL = "https://shavkunov.tk/";
ApiServices apiServices;
public String stat_auth;
TextView msg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);
//some variables
}
public void postRequest() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
apiServices = retrofit.create(ApiServices.class);
Call<Posts> call = apiServices.createPost("1naesis@gmail.com", "1");
call.enqueue(new Callback<Posts>() {
@Override
public void onResponse(Call<Posts> call, Response<Posts> response) {
if (response.isSuccessful()) {
switch (response.code()) {
case 200 :
Log.d("otvet", "" + response.body());
break;
case 201 :
break;
}
}
else {
Toast.makeText(MainActivity.this, "упс", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<Posts> call, Throwable t) {
Toast.makeText(MainActivity.this, "error: "+ t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
public void onClickSignIn(View view) { //текст-кнопка "
postRequest();
}
}
Please, help me)