在 flutter web 中发生 XMLHttpRequest 错误时启用 CORS [英] Enable CORS while an XMLHttpRequest error occurs in flutter web

查看:59
本文介绍了在 flutter web 中发生 XMLHttpRequest 错误时启用 CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用该函数将数据添加到数据库时,并且在服务器上我添加了Access-Control-Allow-Origin 以便它不会被 CORS 阻止,但是当我查看浏览器控制台工具选项卡控制台

when I will add data to the database using the function, and on the server I have added Access-Control-Allow-Origin so that it is not blocked by CORS, but still error when I looked in the browser console tools tab console

Access to XMLHttpRequest at 'https://int.goo.id/api/pg/sso.register' from origin 'http://127.0.0.1:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

如何停用 CORS??

how to deactivate CORS??

推荐答案

对于使用 node.js 服务器的任何人,请在您的服务器端代码中启用 cors 支持.

For anyone who is using node.js server, enable cors support in your server side code.

  1. npm i cors express
  2. 在 index.js 或 server.js 中 -

const express = require("express");

const app = express();
var cors = require("cors");
app.use(cors()); 

这应该可以解决 flutter web 的 cors 问题

This should fix cors issue with flutter web

这篇关于在 flutter web 中发生 XMLHttpRequest 错误时启用 CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆