无法在 Firefox 中获取/发布数据
每当我在浏览器中输入 localhost:8080/insert 时,我都会使用以下代码将数据发布到数据库
router.post('/insert',async(req,res)=>{
const data =new model({
name: 'GLX SHAHIN 3',//req.body.name,
price: 7100000,//req.body.price,
count: 5//req.body.count
})
try{
const save= await data.save();
res.status(200).json(save);
Console.log('inserted.');
}
catch(err){
res.status(404).json({message: err.message});
}});
,我收到此错误:
cannot get /insert
并且 Firefox 控制台显示:
内容安全策略:页面的设置阻止加载http://localhost:8080/favicon.ico(“default-src”)上的资源。
I use following code to post data to database
router.post('/insert',async(req,res)=>{
const data =new model({
name: 'GLX SHAHIN 3',//req.body.name,
price: 7100000,//req.body.price,
count: 5//req.body.count
})
try{
const save= await data.save();
res.status(200).json(save);
Console.log('inserted.');
}
catch(err){
res.status(404).json({message: err.message});
}});
whenever I enter localhost:8080/insert in browser, I get this error:
cannot get /insert
and Firefox console say:
Content Security Policy: The page’s settings blocked the loading of a resource at http://localhost:8080/favicon.ico (“default-src”).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每当您从浏览器向端点发出请求时,默认情况下它都会发送 GET 请求。由于您的路线是
router.post()
而不是router.get()
您会收到错误can not get/insert
如果您想测试您的 POST 端点,您必须使用 postman 之类的应用程序。
如果您足够大胆,还可以使用 cURL
Whenever you make request to an endpoint from browser, it will send a GET request by default. Since your route is
router.post()
notrouter.get()
you get the errorcan not get/insert
If you want to test your endpoint for POST, you will have to use application like postman.
If you are daring enough you can also use cURL