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

210
Vistas
TypeError on fetch request on "e-raktakosha" web site api

I am new to javascript. I was trying to make an api call. My code

const options = {
  method: 'GET',
  headers: {
    Authorization: 'Basic dW5kZWZpbmVkOnVuZGVmaW5lZA==',
    'content-type': 'application/json',
  }
};
fetch(
  'https://www.eraktkosh.in/BLDAHIMS/bloodbank/nearbyBB.cnt?hmode=GETNEARBYSTOCKDETAILS&stateCode=21&districtCode=378&bloodGroup=all&bloodComponent=11&lang=0',
  options
)
  .then((response) => response.json())
  .then((response) => console.log(response))
  .catch((err) => console.error(err));

but I encountered with an error saying

Error: Failed to fetch
  1. This api call works perfectly with Hoppscotch
  2. If I try to hit the url right on my url bar, it also works fine.

Any help is strongly appreciated. Thank you from Manoranjan

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Please don't use body with a get request. The GET request is purely meant to collect back data from server, which allows you to sent Queries, not data on the request. Just remove body:'false' or use body:false. The best way is to remove the body from your request so unexpected input is not sent via this GET request.

about 4 years ago · Juan Pablo Isaza Denunciar

0

As other People already mentioned, you can't pass a Body when doing a GET HTTP call, instead you can pass Query Params

Notice this part on the URL

hmode=GETNEARBYSTOCKDETAILS&stateCode=21&districtCode=378&bloodGroup=all&bloodComponent=11&lang=0

Still looking into the code it seems the server have a cors policy, look at this sandbox

See this codesandbox -> https://codesandbox.io/s/peaceful-mcclintock-exuzol?file=/src/index.js

Summary:

  • GET accept body/payload but it could cause errors, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET

  • Using the Web API (new headers, new request) for doing the HTTP call

GET warning of body/payload usage

It is better to just avoid sending payloads in GET requests.

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