如何创建 POST 请求并检索其信息?



所以,呃,我在一个大的不和谐机器人列表项目工作,我需要帮助,我使用PUGJS和Javascript,我想在我的网站上发布信息到一个特定的URL并检索它,事情是我不知道我如何才能真正发布请求,我试图这样做使用这个:

routes.js

router.get('/api/bots', (req, res) => {
res.send({})
});
router.get('/newbot', (req, res) => res.render('dashboard/newbot', { icon: process.env.ICON3 }))

newbot.pug:

h1.display-5 Lenox Bot List - Add Bot
form(action='/api/bots', method='post')
label(for='BotID') Bot ID:
hr
input#team_name(type='String', value='', placeholder='Enter your Bot ID')
hr
input.a.button.btn.btn-success(type='submit', value='Submit bot')     

当我发布到api/bots时,代码不起作用。我没有在里面找到任何身份证明。有人能好心地帮帮我吗?谢谢你!

您需要创建一个用于创建post请求的post路由

router.post('/api/bots', (req, res) => {
res.send({})
});

另外,你应该使用

form(action='/api/bots', method='POST') in form with大写字母

最新更新