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
How do I make fetch from localhost not return 400 (Bad Request)?

I use to make a fetch request from localhost. The javascript for that was inside a script tag inside the index.html file:

<!DOCTYPE html>
<html lang="en">
    <head>
        ...
    </head>
    <body>
        ...
  
        <script type="text/javascript">
            ...
           var config = {}
           for (var file in guis) config[file] = guis[file].getValue()

           fetch('/one/two/three', {method: 'POST', body: JSON.stringify({type: type, config: config }) })
               .then(response => response.json())
               .then(function(test) {
                   if ('href' in test) {
                       setCookie("test_str", test['href'].split('http:',2)[1])
                       SomeFuction();
                       JumpTo();
                   } else {
                       var alert_message = `Can't run test. ${test.detail}`;
                       window.alert(alert_message);
                       JumpTo();
                   }
               })
               .catch(function (err) {
                   var alert_message = `Can't run test: ${err}`;
                   window.alert(alert_message);
               })
            ...
        </script>
    </body>
</html>

and it worked. But after a while I moved all the javascript (~800 lines), to an external file and I imported it like usually:

<script src="./index.js"></script>

and after that I started getting

POST http://172.17.0.2/one/two/three 400 (Bad Request)

How do I fix this error?

about 4 years ago · Juan Pablo Isaza
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