node.js - React.js, Node.js : 在 React 中发送 axios 请求
问题描述
我尝试使用 axios 在 react 中发送带有电子邮件和密码的请求。 React 应用程序:
console.log(`
--SUBMITTING--
First Name: ${this.state.firstName}
Last Name: ${this.state.lastName}
Email: ${this.state.email}
Password: ${this.state.password}
`);
this.sendData(this.state.email, this.state.password);
// this.changeRoot("calendar");
} else {
console.error("FORM INVALID - DISPLAY ERROR MESSAGE");
}
};
sendData(login, password) {
console.log("login -> " + login);
console.log("passwor -> " + password);
axios.post('http://localhost:9000/signup', { email: login, psswd: password })
.then((rep) => { console.log(rep) })
.catch((error) => { console.log(error) });
}
登录名和密码中的数据都可以。节点服务器:
app.post('/signup', (req, res, next) => {
console.log("login -> " + req.body.email);
console.log("psswd -> " + req.body.psswd);
});
所以感谢所有的帮助。
解决方案
只是猜测,但是,您似乎没有配置 bodyParser() 中间件(将数据从 HTTP 请求解析到req.body
.
请参阅此相关答案
推荐阅读
- mariadb - Moodle 数据库转储无法恢复
- python - 从 QIODevice.read() 读取后如何处理数据?
- android - Workmanager 不使用 APPEND 策略执行唯一作业
- python - Anaconda Python 内核因 DLL 错误而死
- java - 无法为 JBoss EAP 6.4 设置 -Dlog4j.configuration JVM 参数
- sql-server - SQL:输出多个左连接行作为csv文件的一条记录
- configuration - Nat - 虚拟服务器配置
- sql - SQL Server 分组依据?
- r - 我可以在同一个 Shiny App 中使用 highcharter 和 ggplot 吗?
- ios - 如何在 UITextField 的 shouldChangeCharactersIn 中有效处理多个文本字段