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

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

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