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

141
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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