Greetings to all! I apologize in advance, for I am new to this business ... The situation is as follows: I want to send a request to the POST website, with the login and password specified by me, and in return receive at least some information. As a result, after sending the request in the log, I get the answer null. Poke what I am doing wrong, the code is below:
My interface:
public interface Link {
@FormUrlEncoded @POST("site/login") Call<User> authentication(@Field(value = "ClientUsers[email]") String email, @Field(value = "ClientUsers[password]") String password); }
User class:
public class User {
public String login; public String password; }
Main activity:
public class MainActivity extends AppCompatActivity {
EditText etEMAIL; EditText etPASS; Button bLOGIN; private static final String URL = "http://labo-pbei.no-ip.org:10001/"; private Gson gson = new GsonBuilder().create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(URL) .addConverterFactory(GsonConverterFactory.create(gson)) .build(); Link link = retrofit.create(Link.class); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etEMAIL = (EditText) findViewById(R.id.etEMAIL); etPASS = (EditText) findViewById(R.id.etPASS); bLOGIN = (Button) findViewById(R.id.bLOGIN); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); bLOGIN.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Call<User> call = link.authentication(etEMAIL.getText().toString(),etPASS.getText().toString()); call.enqueue(new Callback<User>() { @Override public void onResponse(retrofit.Response<User> response, Retrofit retrofit) { Log.d("LOGO", String.valueOf(response.body())); } @Override public void onFailure(Throwable t) { } }); } }); } }
bodysomething? It is necessary to look at HTTP statuses first, communication errors, then in the response body. - Eugene Krivenja