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

208
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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