Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
Retrofit Android Developer not working with rest_framework in Python-Django

i'm having issues getting Retrofit 2.0 to send POST requests to Python-Django.

Here's my Retrofit method.

   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();
            }
        }
    });
} 

Here's my interface method used in the Rest call:

public interface UserService {
@POST("rest/cadastro")
Call<User> createAccount(@Body User user);

}

And here's my traceback error:

04-03 12:58:43.726 18692-18692/com.example.ccyrobuosi.estudos E/heurys: Failed to connect to /127.0.0.1:8000

In advance, my Python code works just fine, i used Postman to test it, and its getting the requests properly.

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda