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

435
Vistas
Why axios request doesnt work(Maybe problem in headers or CORS)?

The following Axios request made via a local server on Redux does not work, giving a CORS error:

    axios.post('server_url', qs.stringify({ 

      "username": "123", 
      "password": "123", 
      "repassword": "123"

    }, { 

      headers: {
        "Accept": "application/json",
        "Content-Type": "application/x-www-form-urlencoded",
      },

    }))

But the request is made through Postman, and even the following python code:

import requests
from requests.structures import CaseInsensitiveDict

url = "server url"

headers = CaseInsensitiveDict()
headers["Accept"] = "application/json"
headers["Content-Type"] = "application/x-www-form-urlencoded"

data = "username='123'&password='123'&repassword='123'"

resp = requests.post(url, headers=headers, data=data)

print(resp.content)

There is no access to the server from the word at all. Maybe it's some kind of headings or something like that?

Error in console

Error in network

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

A message or any request through axios must return a promise because the request to the server is an asynchronous operation. For example:

const url = "http://somedomen.org";
axios.post(
  url,
  { name: "John", pass: 1, repass: 1 },
  {
    headers: {
      Accept: "application/json",
      "Content-Type": "application/x-www-form-urlencoded",
    },
  },
).then(res => {
  return  res.data
})

Also you can use async/await sintaxis

async function func() {
  const url = "http://somedomen.org";

  const response = await axios.post(
    url,
    { name: "John", pass: 1, repass: 1 },
    {
      headers: {
        Accept: "application/json",
        "Content-Type": "application/x-www-form-urlencoded",
      },
    },
  )

  return response.data
}

Or to destructure the response variable

async function func() {
  
  const { data, status, headers } = await axios.post(
    //your condition...
  );

  return {
    data,
    status,
    headers,
  };
}

Until you have returned the promise of a result, the request cannot be completed. I hope I helped you

about 4 years ago · Santiago Trujillo 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