【问题标题】:Flutter - XMLHttpRequest has been bloked by CORS policyFlutter - XMLHttpRequest 已被 CORS 策略阻止
【发布时间】:2021-09-05 02:43:51
【问题描述】:

我正在研究 Flutter,在我的 php API 中,我放置了这些标头:

header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET');
header("Access-Control-Allow-Headers: X-Requested-With");

但我仍然有答案:

Access to XMLHttpRequest at 'http://localhost/spring_box/api.php' from origin 'http://localhost:52502' has been blocked by CORS policy: The 'Access-Control-Allow-Origin'

你能帮我解决我的问题吗?

【问题讨论】:

    标签: php json api flutter


    【解决方案1】:

    按照以下步骤进行

    1- 转到flutter\bin\cache 并删除一个名为:flutter_tools.stamp 的文件

    2- 进入 flutter\packages\flutter_tools\lib\src\web 并在文本编辑器中打开文件 chrome.dart。

    3- 搜索和查找“--disable-extensions”

    4- 添加'--disable-web-security'

    5- 保存。立即尝试

    快乐编码。

    【讨论】:

      猜你喜欢
      • 2021-10-27
      • 2018-02-26
      • 2021-04-24
      • 2019-12-18
      • 2019-10-31
      • 2019-04-28
      • 2021-10-05
      • 2022-08-14
      • 1970-01-01
      相关资源
      最近更新 更多