Android developer refurbishment not working with rest_framework in Python-Django

I am having trouble getting Retrofit 2.0 to send POST requests to Python-Django.

Here's my refit 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 is my tracing 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 get requests correctly.

+3
java python django retrofit2 android-developer-api


source to share


No one has answered this question yet

See similar questions:

391
How do I add a permission manifest for an app?
61
test localhost in android emulator

or similar:

2097
Is there a way to run Python on Android?
611
What is __future__ in Python, which is used and how / when to use it, and how does it work
578
Can Java 8 be used for Android development?
566
Updating Eclipse with Android Development Tools v. 23
428
Creating a JSON response using Django and Python
242
Django development development
197
Setting up Python setup.py vs install
1
Why can't my application read JSON from my API?
1
What is Retrofit OR Operator for Search
0
How to make calls to unreleased locally hosted api from physical android client?



All Articles
Loading...
X
Show
Funny
Dev
Pics