Node JS 应用程序不从邮递员那里获取值
Node JS Application not taking Values from postman
我写了两个节点 js 应用程序,它们正在正确获取数据,但它们没有采用 post 值第一个应用程序是这个 TinderClone 这只是一个没有前端的 api 我我正在 posting 来自 postman 的数据,它返回自动生成的 ID 但不是我正在 posting,
的数据
我从 github 克隆的其他应用程序,它有正确的前端和工作 CRUD,但是当我尝试从 postman 获取 post 值时,它不会接受任何值,它只会在数据库中添加空值记录,那么我在 postman 上做错了什么?因为如果我 post 数据在其前端使用表单,它仍然有效应用程序 url 是 MernCRUD
邮递员截图:
posting data,
fetching data
代码:
//Cards Schema (Cards.js)
import mongoose from 'mongoose'
const cardSchema = mongoose.Schema({
name: String,
imgUrl: String
})
export default mongoose.model('cards', cardSchema)
//Posting Data (Server.js)
app.post('/tinder/cards', (req, res) => {
const dbCard = req.body;
Cards.create(dbCard, (err, data) => {
if(err){
res.status(500).send(err)
}
else{
res.status(201).send(data)
}
})
})
//Fetching Data
app.get('/tinder/cards', (req, res) => {
Cards.find((err, data) => {
if(err){
res.status(500).send(error);
}
else{
res.status(200).send(data);
}
});
});
在邮递员中,您不必手动添加内容类型。您应该从下拉列表中选择 select json,默认情况下它会添加内容类型。 **
现在您的原始下拉列表中的文本更改为 json。
**
我写了两个节点 js 应用程序,它们正在正确获取数据,但它们没有采用 post 值第一个应用程序是这个 TinderClone 这只是一个没有前端的 api 我我正在 posting 来自 postman 的数据,它返回自动生成的 ID 但不是我正在 posting,
的数据我从 github 克隆的其他应用程序,它有正确的前端和工作 CRUD,但是当我尝试从 postman 获取 post 值时,它不会接受任何值,它只会在数据库中添加空值记录,那么我在 postman 上做错了什么?因为如果我 post 数据在其前端使用表单,它仍然有效应用程序 url 是 MernCRUD
邮递员截图: posting data, fetching data
代码:
//Cards Schema (Cards.js)
import mongoose from 'mongoose'
const cardSchema = mongoose.Schema({
name: String,
imgUrl: String
})
export default mongoose.model('cards', cardSchema)
//Posting Data (Server.js)
app.post('/tinder/cards', (req, res) => {
const dbCard = req.body;
Cards.create(dbCard, (err, data) => {
if(err){
res.status(500).send(err)
}
else{
res.status(201).send(data)
}
})
})
//Fetching Data
app.get('/tinder/cards', (req, res) => {
Cards.find((err, data) => {
if(err){
res.status(500).send(error);
}
else{
res.status(200).send(data);
}
});
});
在邮递员中,您不必手动添加内容类型。您应该从下拉列表中选择 select json,默认情况下它会添加内容类型。 **
现在您的原始下拉列表中的文本更改为 json。
**