Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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);
  }
  
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading