为了账号安全,请及时绑定邮箱和手机立即绑定

Post 请求正文为空 - XMLHttpRequest 到 Express 服务器

Post 请求正文为空 - XMLHttpRequest 到 Express 服务器

qq_花开花谢_0 2021-06-22 22:11:45
我正在尝试从使用 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!");.
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 216 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信