Tengo problemas para que Retrofit 2.0 envíe solicitudes POST a Python-Django.
Aquí está mi método de actualización.
public void sendNetworkRequest(User user) { //Cria instância retrofit final Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://127.0.0.1:8000/") .addConverterFactory(GsonConverterFactory.create()) .build(); UserService services = retrofit.create(UserService.class); Call<User> call = services.createAccount(user); call.enqueue(new Callback<User>() { @Override public void onResponse(Call<User> call, Response<User> response) { Toast.makeText(CadastrarActivity.this, "Você foi cadastrado com sucesso!", Toast.LENGTH_SHORT).show(); } @Override public void onFailure(Call<User> call, Throwable t) { CheckConnection checkConnection = new CheckConnection(); if (checkConnection.equals(null)){ Toast.makeText(CadastrarActivity.this, "Conecte-se a internet!", Toast.LENGTH_SHORT).show(); } else { Log.e("heurys", t.getMessage()); System.out.println(t.getStackTrace()); Toast.makeText(CadastrarActivity.this, "Algo deu errado!", Toast.LENGTH_SHORT).show(); } } }); }Aquí está mi método de interfaz utilizado en la llamada Rest:
public interface UserService { @POST("rest/cadastro") Call<User> createAccount(@Body User user);}
Y aquí está mi error de rastreo:
04-03 12:58:43.726 18692-18692/com.example.ccyrobuosi.estudos E/heurys: Failed to connect to /127.0.0.1:8000De antemano, mi código de Python funciona bien, usé Postman para probarlo y está recibiendo las solicitudes correctamente.