ReactJS Axios和Node.js-数据未定义?

问题描述

我在ReactJS中使用Axios向我的node.js服务器发出了发布请求。它的作用是发送自动电子邮件

现在我正尝试将数据从Axios调用传递到我的node.js服务器,例如,我在这里传递{test:“ abc”},但是在我的node.js服务器中,req.test将是未定义。

我在某个地方犯了错误吗?

ReactJS axios POST呼叫

axios
  .post("http://localhost:3000/send",{
    data: {
      test: "abc",},})
  .then((response) => {
    console.log(response);
  });

Node.js应用程序(在端口3000上监听)

app.post("/send",(req,res) => {
    console.log(req.test); // undefined
    const output = `<h3>Message</h3>`;

    // create reusable transporter object using the default SMTP transport
    let transporter = nodemailer.createTransport(smtpTransport({
        name: "sj9",host: "mail.sj9.co",port: 465,secure: true,// true for 465,false for other ports
        auth: {
          user: "test@sj9.co",// generated ethereal user
          pass: "jailbreak",// generated ethereal password
        },tls: {
          rejectUnauthorized: false,}));

    // setup email data with unicode symbols
    let mailOptions = {
        from: '"My Name" <test@sj9.co>',// sender address
        to: "my-email@gmail.com",// list of receivers
        subject: "Node Contact Request",// Subject line
        text: "Hello world?",// plain text body
        html: output,// html body
    };

    // send mail with defined transport object
    transporter.sendMail(mailOptions,(error,info) => {
        if (error) {
          return console.log(error);
        }
        console.log("Message sent: %s",info.messageId);
        console.log("Preview URL: %s",nodemailer.getTestMessageUrl(info));
    });
});

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)