Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

757
Visualizações
TypeError: Network request failed (using ReactNative and Django)

I'm developing a mobile app with React Native, and have a REST API in Django at the backend. I want to make a POST request from the app to my API.

Code

function sendDpi() {
const requestOptions = {
  method: 'POST',
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    dpi: imageDpi,
  }),
};
fetch('http://127.0.0.1:8000/', requestOptions)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => {
    console.log(error);
  });
}

When sendDpi() is called by my app, I get [TypeError: Network request failed].
127.0.0.1:8000 is where my Django app is running. I've tried using my IP address (as pointed out by this answer) as well.
I've also modified android/app/src/main/AndroidManifest.xml to include android:usesCleartextTraffic="true".

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I think 127.0.0.1:8000 is also localhost. You need to find your external ip address if you use a physical device to test from.

I you test from android emulator you can just use http://10.0.2.2/8000.

Also try to make it work with http first. You might not have a valid SSL certificate. With invalid SSL certificate you also get [TypeError: Network request failed]

over 4 years ago · Santiago Trujillo Relatório

0

The suggestion made before was great except the URL needed should be http://10.0.2.2:8000 instead of http://10.0.2.2/8000

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda