我正在尝试从使用 XMLHttpRequest 发送到快速服务器的 post 请求访问正文。然而,请求的正文是空的,我似乎无法理解为什么会这样。我在 express 应用程序中包含了一个正文解析器,并且我试图从 SO 答案中复制一些代码。但我仍然以某种方式弄错了。<script> const Http = new XMLHttpRequest(); Http.open('post', 'localhost:3000'); Http.send("sending something!");// this resolves to {} on the backend? Http.onload = function() { alert(Http.response); };</script>这就是我尝试在我的快速服务器上处理它的方式const express = require("express");let app = express()const bodyParser = require("body-parser");app.use(bodyParser.urlencoded({ extended: true}));app.post("/post", (req, res) => { console.log("inside of post"); console.log(req.body);})app.listen(3000)这是日志inside of post{}我希望console.log()打印“发送东西!” 我尝试使用Http.send("sending something!");.
添加回答
举报
0/150
提交
取消