gpt4 book ai didi

mysql - Node.js Post 方法请求不起作用 {"statusCode":404 ,"error" :"Not Found" ,"message" :"Not Found"}

转载 作者:行者123 更新时间:2023-11-29 18:22:41 28 4
gpt4 key购买 nike

我对 Node.js 相当陌生,我使用的是下面页面中的教程。

http://www.9lessons.info/2017/02/create-restful-api-nodejs-mysql.html

现在遇到的问题是 post 方法。当我调用 Get 方法以外的任何其他方法时,我收到此错误:

https://github.com/srinivastamada/NodeRestful/blob/master/server.js

server.route({
method: 'POST',
path: '/messages',

handler: function (request, reply) {

const uid = request.payload.uid;
console.log(uid);

connection.query('SELECT * FROM messages WHERE uid_fk = "' + uid + '"', function (error, results, fields) {
if (error) throw error;
console.log(results);
reply(results);
});
},
config: {
validate: {
payload: {
uid: Joi.number().integer()
}
}

}
});

最佳答案

首先您需要将数据插入消息表中。

然后点击来自 POSTMAN 的 post 请求。见下图。

enter image description here

关于mysql - Node.js Post 方法请求不起作用 {"statusCode":404 ,"error" :"Not Found" ,"message" :"Not Found"},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46440451/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com