Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

768
Views
TypeError: la solicitud de red falló (usando ReactNative y Django)

Estoy desarrollando una aplicación móvil con React Native y tengo una API REST en Django en el backend. Quiero hacer una solicitud POST desde la aplicación a mi API.

Código

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

Cuando mi aplicación llama a sendDpi() , obtengo [TypeError: Network request failed] .
127.0.0.1:8000 es donde se ejecuta mi aplicación Django. También intenté usar mi dirección IP (como se indica en esta respuesta).
También modifiqué android/app/src/main/AndroidManifest.xml para incluir android:usesCleartextTraffic="true" .

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Creo que 127.0.0.1:8000 también es localhost. Debe encontrar su dirección IP externa si usa un dispositivo físico para realizar la prueba.

Si prueba desde el emulador de Android, puede usar http://10.0.2.2/8000 .

También intente hacer que funcione con http primero. Es posible que no tenga un certificado SSL válido. Con un certificado SSL no válido, también obtiene [TypeError: Network request failed]

over 4 years ago · Santiago Trujillo Report

0

La sugerencia hecha antes fue excelente, excepto que la URL necesaria debería ser http://10.0.2.2:8000 en lugar de http://10.0.2.2/8000

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!