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

149
Views
¿No hay cuerpo en una solicitud GET usando la API de búsqueda?

Estoy enviando (más bien tratando de) enviar una solicitud GET a mi servidor utilizando la API de recuperación nativa de JavaScript con un cliente HTML. En cartero puedo hacer esto, sin problemas, ¿qué pasa?

Aquí está el error:

 Unhandled Promise Rejection: TypeError: Request has method 'GET' and cannot have a body

Nuevamente, necesito hacer una solicitud GET, no una solicitud posterior... El cartero permite esto.

Aquí está el código:

 fetch('http://www.localhost:3000/get-data', { method: 'GET', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ a: 1, story: document.getElementsByTagName("input")[0].value, }) });

PD: Yo uso Safari, pero Chrome, aunque marca un error de aspecto diferente que transmite el mismo mensaje, sigue sin funcionar.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La especificación HTTP no menciona un cuerpo en una solicitud GET. El servidor debe operar solo en el URI.

El problema aquí es que Postman está permitiendo algo que no está permitido por la especificación. el navegador tiene razón.

Si desea enviar un cuerpo, use un método POST .

Por ejemplo:

 const response = await fetch(url, { method: 'POST', // *GET, POST, PUT, DELETE, etc. mode: 'cors', // no-cors, *cors, same-origin cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached credentials: 'same-origin', // include, *same-origin, omit headers: { 'Content-Type': 'application/json' // 'Content-Type': 'application/x-www-form-urlencoded', }, redirect: 'follow', // manual, *follow, error referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url body: JSON.stringify(data) // body data type must match "Content-Type" header });

Código cortesía de MDN

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