这个问题是由于服务器返回的 'Access-Control-Allow-Origin' 头部包含了多个值引起的。根据错误信息,可以看到头部包含了两个 '*' 值。

要解决这个问题,可以通过修改服务器的配置来确保只返回一个值。

在 nginx 配置文件中,找到对应的 location 配置,并添加以下内容:

location /jeecg-boot/sys/randomImage/ {
    add_header Access-Control-Allow-Origin http://localhost:8080;
    add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
    add_header Access-Control-Allow-Headers 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
    add_header Access-Control-Expose-Headers 'Content-Length,Content-Range';
}

这将确保只有 'http://localhost:8080' 可以访问该接口,并且只返回一个值给 'Access-Control-Allow-Origin' 头部。

修改完配置后,重启 nginx 服务使配置生效

Access to XMLHttpRequest at http102451816890jeecg-bootsysrandomImage1690281359633 from origin httplocalhost8080 has been blocked by CORS policy The Access-Control-Allow-Origin header contains multiple

原文地址: http://www.cveoy.top/t/topic/ii48 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录