【问题标题】:Json cant go through webhook call on form submitJson 在表单提交时无法通过 webhook 调用
【发布时间】:2025-12-30 23:35:14
【问题描述】:

我有 axios 的表单提交功能:

const onSub mit = (data) => {
  const webhookUrl = 'MY URL';
  const info = JSON.stringify(data);

   axios({
     method: 'post',
     url: `${webhookUrl}`,
     data: info,
     config: { headers: { 'Content-Type': 'application/json' } },
   })
     .then(function (response) {
       alert('Message Sent!');
     })
     .catch(function (response) {
       //handle error
       console.log(response);
     });
 };

这是我在JSON.stringify 内部info 之后得到的:

{"fullname":"Temirlan","email":"test@mail.com","phone":"0179890808","proffesion":false,"message":"test"}

这是我在提交表单后在我的 webhook 中得到的,这是错误的:

但是,如果我使用迅雷客户端并发布相同的数据:

我理解正确:

我做错了什么?

【问题讨论】:

    标签: javascript json reactjs axios webhooks


    【解决方案1】:

    所以我对 axios 使用了不同的方法并且它起作用了:

    let axiosConfig = {
      headers: {
       'Content-Type': 'application/json;charset=UTF-8',
       'Access-Control-Allow-Origin': '*',
     },
    };
    axios
     .post(webhookUrl, info, axiosConfig)
     .then((res) => {
       console.log('RESPONSE RECEIVED: ', res);
     })
     .catch((err) => {
       console.log('AXIOS ERROR: ', err);
     });
    

    【讨论】: