Home > OS >  What should I do to fix this error when sending the form to the server?
What should I do to fix this error when sending the form to the server?

Time:06-12

have a good time! I use axios to send a post request to the api http://freerealapi.com/ I work based on the document but it gives me an error 400 What should I do?

const buildDiscount = async token => {
  let data = new FormData();
  data.append('title', keyCodes);
  data.append('text', 'test text');
  data.append('image', file);
  data.append('tags', 'one,two,three');
  try {
      const res = await axios.post('https://api.freerealapi.com/panel/blogs/', data, {
        headers: {
          'Content-Type': 'multipart/form-data',
          Authorization:  `Bearer ${token}`,
        },
      })        
      
      console.log(res.data);

  } catch (error) {
      console.log(error.response);
  }
  
}

CodePudding user response:

This function is most probably missing those 2 extra variables ( keyCodes, file ), can you provide those inputs to the function? That's probably the reason why the request is being malformed.

  • Related