晚上好,我正在尝试将 req.body 记录到控制台,但它说它是未定义的,即使当我执行 console.log(req) 时,主体及其内容都会显示出来。我正在尝试制作 Twilio 文本应用程序。我迷失了,我不确定它是否说身体未定义,即使它已定义。任何指导表示赞赏。/* Nodejs index.js */const express = require('express')const app = express()const port = 3000const bodyParser = require('body-parser');const indexRouter = require('./routes/index-router');/* View Engine */const ejs = require('ejs');app.set('view engine', 'ejs');app.use('/', indexRouter);app.use(express.static('public'));app.use(express.urlencoded({ extended: true }));app.use(bodyParser.json());app.get('*', (req, res) => { res.sendStatus(404);})app.listen(port, () => { console.log(`Twilio app listening at http://localhost:${port}`)})/* Index Router */var express = require('express');var router = express.Router();var path = require('path');const bodyParser = require('body-parser');router.use(bodyParser.json());require('dotenv').config();var accountSid = process.env.ACCOUNT_SID; // Your Account SID from www.twilio.com/consolevar authToken = process.env.AUTH_TOKEN; // Your Auth Token from www.twilio.com/consolevar twilio = require('twilio');var client = new twilio(accountSid, authToken); /* GET home page. */router.get('/', function (req, res, next) { res.render('index') }); /*Twilio */router.post('/', (res, req) => { /* client.messages.create({ body: `${req.body.text}`, to: '+17185412931', // Text this number from: '+12058946009' // From a valid Twilio number }) .then((message) => console.log(message.sid)); */ console.log(req);}) module.exports = router;/* AJAX Request */$('#text').on('submit', function (e) { e.preventDefault(); const message = $("#message").val(); const data = { message: message, };});
添加回答
举报
0/150
提交
取消