0

我使用 WAMP 在我的电脑上测试东西。我已经建立了一个 React 网站,我正在测试图像上传功能,但我一直遇到这个错误:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost/Image/Upload. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost/Image/Upload. (Reason: CORS request did not succeed).

在进行了大量的谷歌搜索和搜索之后,我做了以下尝试修复它:

  • 启用标头模块
  • 添加了以下内容:
<IfModule mod_headers.c>
    # Accept cross-domain requests
    Header set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"
    Header always set Access-Control-Allow-Methods 'GET, POST, PATCH, PUT, DELETE, OPTIONS'
</IfModule>

httpd.confhttpd-vhosts.conf

  • 将 WAMP 更新到最新版本 (3.2.3)
  • 在 vhosts 配置中更改Require localRequire all granted

现在我被困住了,我想知道我该如何解决这个问题。任何帮助表示赞赏

4

0 回答 0