跨域无法获取 物联平台数据

Blade 未结 1 69
SDLY_20250610
SDLY_20250610 剑侠 2025-07-17 14:23

一、该问题的重现步骤是什么?

1. 组态系统 数据源绑定  设备数据绑定时 出现了跨域无法获取 物联平台数据问题,请问如何设置解决。

2. 部署用的宝塔部署方式。

3.


二、你期待的结果是什么?实际看到的又是什么?


三、你正在使用的是什么产品,什么版本?在什么操作系统上?


四、请提供详细的错误堆栈信息,这很重要。


五、若有更多详细信息,请在下面提供。

1条回答
  • 2025-07-17 16:08

    nginx配置需要加跨域的设置

         # 隐藏后端返回的 CORS 头部
            proxy_hide_header 'Access-Control-Allow-Origin';
            proxy_hide_header 'Access-Control-Allow-Methods';
            proxy_hide_header 'Access-Control-Allow-Headers';
            proxy_hide_header 'Access-Control-Allow-Credentials';
            proxy_hide_header 'Access-Control-Expose-Headers';
            proxy_hide_header 'Access-Control-Max-Age';
            
            # 所有非OPTIONS请求的CORS头部
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
            add_header 'Access-Control-Allow-Headers' 'DNT,X-Requested-With,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,token,Blade-Auth,Blade-Requested-With,Tenant-Id' always;
            add_header 'Access-Control-Allow-Credentials' 'true' always;
            add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
            
            
            # 处理OPTIONS预检请求
            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
                add_header 'Access-Control-Allow-Headers' 'DNT,X-Requested-With,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,token,Blade-Auth,Blade-Requested-With,Tenant-Id' always;
                add_header 'Access-Control-Max-Age' 3600;  # 预检请求的缓存时间
                add_header 'Content-Length' 0;
                add_header 'Content-Type' 'text/plain charset=UTF-8';
                return 204;  # 返回204响应,表示成功,但不返回数据
            }


    如果是java服务,看下面的配置


    CleanShot20250717160927@2x.png


    如果是nginx反向代理,看这里的配置

    CleanShot20250717160901@2x.png

    0 讨论(0)
代码语言
提交回复