CNode

superagent使用post服务器端无法接收到数据

问答
Sstop2stare发布于10 年前最后回复10 年前3 回复4538 浏览0 收藏

传数据

superagent
	.post('http://localhost:5100/api/todo')
	.send({
		id: 1111,
		content: 2222,
		complete: undefined
	})
	.end(function(res) {
		console.log(res)
	})

服务器

app.post('/api/todo', function(req, res, next) {
    console.log(req.body, req.query, req.params);
})

结果打印出来就是undefined {} {} 请问是哪里出错了?

查看回复

回复 (3)

C
cctv1005s#1·10 年前

用了中间件 body-parser了吗?

S
stop2stare#2·10 年前
引用 cctv1005s用了中间件 body parser了吗?

@cctv1005s 我试试。。。桥豆麻袋。。

S
stop2stare#3·10 年前
引用 cctv1005s用了中间件 body parser了吗?

@cctv1005s 解决了。多谢。以前传参数的时候没有注意到使用这个,一直都OK的。我先去看看这个东西到底做什么用的。

参与回复
登录后即可参与回复。登录