Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 发布http表单数据请求不是';t工作,但在邮递员上显示200毫秒状态_Node.js_Json_Express_Mongoose_Postman - Fatal编程技术网

Node.js 发布http表单数据请求不是';t工作,但在邮递员上显示200毫秒状态

Node.js 发布http表单数据请求不是';t工作,但在邮递员上显示200毫秒状态,node.js,json,express,mongoose,postman,Node.js,Json,Express,Mongoose,Postman,我在发布表单数据时遇到问题。 原始方法和xxx URL也可以工作,但在发送表单数据post请求的情况下 我在控制台上收到一个错误 错误如下所示 (节点:12820)未经处理的PromisejectionWarning:ValidationError:登录验证失败:电子邮件:需要路径“email”,密码:需要路径“password”。 在model.Document.invalidate处 //hers' the headers const express = require('express')

我在发布表单数据时遇到问题。 原始方法和xxx URL也可以工作,但在发送表单数据post请求的情况下 我在控制台上收到一个错误 错误如下所示 (节点:12820)未经处理的PromisejectionWarning:ValidationError:登录验证失败:电子邮件:需要路径“email”,密码:需要路径“password”。
在model.Document.invalidate处

//hers' the headers
const express = require('express');
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extend: true }));
const mongoose = require('mongoose');

// here's the function to post requests

function registration() {
  app.post('/login', async (req, res) => {
    const model = new Model({
      email: req.body.email,
      password: req.body.password,
    });
    res.send('posted');
    const result = await model.save();
    console.log(result);
  });
}

//here's the mongo portion


const port = process.env.port || 3000;
app.listen(port, () => console.log(`listening to port ${port}`));

mongoose
  .connect('mongodb://localhost:27017/Login', {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  })
  .then(() => console.log('connected mfs'))
  .catch((err) => console.error('error found...', err));

const LoginSchema = new mongoose.Schema({
  email: { type: String, required: true },
  password: { type: String, required: true },
});

const Model = mongoose.model('login', LoginSchema);

你是用邮递员寄出你的请求吗?是的。你的小小帮助可以帮我节省时间。你在标题中包含了
Content-type:application/json
?我已经提到了我使用的所有标题<代码>app.use(express.json());use(express.urlencoded({extend:true}))我的意思是,你是否在邮递员的标题中包含了
内容类型