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
source to share
No one has answered this question yet
See similar questions:
or similar: