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

167
Visualizações
location.assign() uses last HTTP verb

Because HTML forms don't allow HTTP requests like PUT or DELETE, only GET and POST, I'm sending the PUT request using the fetch API. And then I'm redirecting the page using location.assign() with the Location header from the 302 server response.

const res = await fetch('https://example.org/test', {
    method: "PUT",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(data)
}).catch(err => console.error(err));

if (res.status >= 300 && res.status < 400) {
    window.location.assign(res.headers.get("Location"));
}

The problem is that the new redirected request is also a PUT request, while I would like that window.location.assign would use a GET request. Why does it use the previous HTTP verb of PUT and how can I prevent that?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I figured it out on myself.

It's not that window.location.assign() uses the last HTTP verb. It's that fetch() will automatically follow the redirects. It has the option redirect which has as default option "follow". There isn't a pretty solution to follow redirects yourself with a different HTTP verb, since the redirect status basically means that the same resource has to be accessed through a different URL. The best solution is thus to let the server respond with a status of 200 Ok and give instructions on how to access the next page. (I just set the Location header).

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