无法在 Firefox 中获取/发布数据

发布于 2025-01-13 04:36:13 字数 602 浏览 2 评论 0原文

每当我在浏览器中输入 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

活泼老夫 2025-01-20 04:36:13

每当您从浏览器向端点发出请求时,默认情况下它都会发送 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() not router.get() you get the error can 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文