使用axios ReactJS发布请求

使用axios ReactJS发布请求,reactjs,axios,Reactjs,Axios,我不熟悉HTTP请求,尝试使用axios提交表单的POST请求,但遇到错误400。我想把我的数据发送到url,它应该是JSON格式的 codesandbox错误很明显,您没有将数据传递给axios post方法。我不确定您在服务器中使用的是哪种验证,但它看起来是这样的 axios({ method: "post", url: "https://frosty-wood-6558.getsandbox.com:443/dishes",

我不熟悉HTTP请求,尝试使用axios提交表单的POST请求,但遇到错误400。我想把我的数据发送到url,它应该是JSON格式的


codesandbox

错误很明显,您没有将数据传递给axios post方法。我不确定您在服务器中使用的是哪种验证,但它看起来是这样的

axios({
    method: "post",
    url: "https://frosty-wood-6558.getsandbox.com:443/dishes",
    headers: { "Content-Type": "application/json" },
    data:{
      name:event.name,
preparation_time:event.preparation_time,
type:event.type,
spiciness_scale:event.spiciness_scale,
    }
  })
    .then(function (response) {
      console.log(response);
    })
    .catch(function (response) {
      console.log(response);
    });
因为它现在抛出错误准备时间验证。不确定服务器端的验证是什么

preparation_time: "Wrong format"

谢谢,是的,我错过了数据。我没有任何验证,我只是在学习如何处理http请求