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

143
Visualizações
Forbidden Request while requesting POST from Axios

I got a forbidden request when sending a POST request using axios.

Here is my axios function:

const headers = {
    'Authorization': `bearer ${JSON.parse(localStorage.getItem('TOKEN'))}`,
    'Content-Type': 'application/json'
}

const getByRelationCode = (data) => {
    const response = Client.post(`${TRACKING_API}/getByRelationCode`, data, {
        headers
    })

    return response
}

And this is the calling function

const getDocument = (relationCode) => {
    await Service.getByRelationCode({ relationCode })
        .then((res) => {console.log(res))
        .catch(err => console.log(err))
}

When I hit the endpoint using postman, the endpoint returned the response. But when i call it using Axios it returns a forbidden request. Is there missing from my code?

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

0

You have miss spelled on your header.

const headers = {
    'Authorization': `Bearer ${JSON.parse(localStorage.getItem('TOKEN'))}`,
    'Content-Type': 'application/json'
}

But in some framework we can customize it. If you have customized it for your own then you can call it as bearer. Though it's not correct to name it like that way.

about 4 years ago · Juan Pablo Isaza Relatório

0

try like this

const config = {
    headers: { 
        'Authorization': `bearer ${localStorage.getItem('TOKEN')}`,
        'Content-Type': 'application/json' }
    }; 

const getByRelationCode = (data) => {
    const response = Client.post(`${TRACKING_API}/getByRelationCode`, data, config)
    return response;
}
about 4 years ago · Juan Pablo Isaza Relatório

0

I think it is happening because you spelled Bearer wrong in your code and the server getting your request but is not able to extract the token from it.

Try it with the correct spelling of Bearer.

const headers = {
    'Authorization': `Bearer ${JSON.parse(localStorage.getItem('TOKEN'))}`,
    'Content-Type': 'application/json'
}
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