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

133
Visualizações
Unable to fetch response for login functionality
 const AUTH = () => {
    const params = JSON.stringify({
      user: {
        user_type: 'customer',
        mobile: '8349222680',
        password: '12345',
      },
    });
    const url = 'https://salon-host-dev.herokuapp.com/api/v1/logins/';
    axios
      .post(url, {
        headers: {
          'content-type': 'application/json',
        },
        body: JSON.stringify({
          data: 'data=' + JSON.stringify(params),
        }),
      })
      .then(response => {
        console.log('--->', response.status);
      });
  };

I am trying to get response from url but unable to that if Params passed in raw body json in postman then i am geeting expected response but not in following code please help

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

0

The syntax for axios post request is below

axios.post(url, params, 
{headers: {'Content-Type':'application/json'}})
.then()

The header should be the 3rd argument to the POST method.

about 4 years ago · Juan Pablo Isaza Relatório

0

axios (and axios.post for that matter) can be called like axios.post(config) axios.post(url[, config]) axios.post(url[, data [, config]]) .... so you've chosen the second pattern,

the data to send is in data property, NOT the body property -

also you DONT need to send JSON, you can send the object

So given

const params = {
  user: {
    user_type: 'customer',
    mobile: '8349222680',
    password: '12345',
  },
};
const url = 'https://salon-host-dev.herokuapp.com/api/v1/logins/';

You can

axios.post({
  url: url,
  headers: {
    'content-type': 'application/json',
  },
  data: params,
})

or

axios.post(url, {
  headers: {
  'content-type': 'application/json',
  },
  data: params,
})

or

axios.post(url, params, {
  headers: {
    'content-type': 'application/json',
  }
})

Additionally, if you rename params to data

const data = {
  user: {
    user_type: 'customer',
    mobile: '8349222680',
    password: '12345',
  },
};

and create a headers variable

const headers = {
  'content-type': 'application/json',
};

you can do any of the following

axios.post(url, data, { headers });
axios.post(url, {data, headers});
axios.post({url, data, headers});
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