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

224
Visualizações
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 à 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