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

299
Visualizações
axios.post is showing error "Request failed with status code 400" but same data is posted by postman

when i am post same "data-object" with same "url-link" in postman, its working and my data is post successfully in postman. but when hit request through axios, there is accoured error "Request failed with status code 400". and my data is not posting. i tried to pass data object of axios, eg, "JSON.stringify(data)" but its not working and showing error "status 400". plez solve my query....

there is axios error

const Axios = require("axios");
export const uploadImages = (data) => async (dispatch) => {
  dispatch({
    type: "UPLOAD_IMAGES_INIT",
  });
  try {
    const result = await Axios.post("http://localhost:4000/postImages", {
      "id":1,
      "name":"Flare Dress",
      "price":12000,
      "salePrice":20000,
      "discount":10,
      "pictures":[
         "/assets/images/fashion/product/1.jpg",
      ],
      "shortDetails":"Sed ut perspiciatis, unde omnis iste natu",
      "description":"Lorem Ipsum is simply dummy text of",
      "stock":16,
      "new":true,
      "sale":true,
      "category":"women",
      "colors":[
         "yellow",
      ],
      "size":[
         "M",
      ],
      "tags":[
         "nike",
      ],
      "rating":4,
      "variants":[
         {
            "color":"yellow",
            "images":"/assets/images/fashion/product/1.jpg"
         },

      ],
      "newPostImages":[
         {
            "images":"/assets/images/fashion/product/1.jpg"
         },
      ]
   });
  } catch (err) {
    const error = err.message || "Error Upload Images";
    dispatch({
      type: "UPLOAD_IMAGES_FAIL",
      payload: error,
    });
  }
};

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

0

I got an answer to this question. There's a difference in the request structure from Postman and my code (No matter if using fetch or Axios). Yeah, it may happen that the current user does not have permissions for some entity, but in this case it's all about the following:

  • Simple answer: You have to choose cookie auth or basic auth.
  • Basic auth: base64 format for user and password.
  • Cookie auth (I'm using this option): Drupal sets a header with a session cookie when doing the login request (Postman is automatic, but in your code request, you need to include and send the same cookie for a POST or PATCH or whatever needs auth). Don't forget to send your token header also.
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