跨域The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only

Posted 奔跑吧前端(李钊)

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了跨域The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only相关的知识,希望对你有一定的参考价值。

使用Ajax跨域请求资源,Nginx作为代理,出现:The ‘Access-Control-Allow-Origin‘ header contains multiple values ‘*, *‘, but only one is allowed 错误。

服务端允许跨域配置:

#region 设置允许跨域,允许复杂请求
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
            if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
            {
                HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,PATCH,OPTIONS");
                HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, Authorization");
                //HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
                HttpContext.Current.Response.End();
            }
            #endregion

  Nginx的配置:

 add_header ‘Access-Control-Allow-Origin‘ ‘*‘;
        location / {
            if ($request_method = ‘OPTIONS‘) {
            add_header Access-Control-Allow-Origin *;
                add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,PATCH,OPTIONS;
                return 200;
            }
            proxy_pass http://xx:8002/;
            #proxy_pass http://localhost:62249/;

  contains multiple values "*" 意思就是设置了2次跨域,但是只有一个是允许的,移除其中的任意一个就好了。如果服务器设置了允许跨域,使用nginx代理里面就不需要了(或者就不用使用Nginx了)

以上是关于跨域The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only的主要内容,如果未能解决你的问题,请参考以下文章

[转]No 'Access-Control-Allow-Origin' header is present on the requested resource.'Ajax跨域访

springboot 解决跨域请求,No 'Access-Control-Allow-Origin' header is present on the requested resour

js跨域访问,No 'Access-Control-Allow-Origin' header is present on the requested resource

ajax跨域处理 No 'Access-Control-Allow-Origin' header is present on the requested resource 问题

浏览器禁止跨域访问及解决: No 'Access-Control-Allow-Origin' header is present on the requested resource.

No 'Access-Control-Allow-Origin' header is present on the requested resource——Web Api跨域问题(示例