跨域问题其他解决方案

前端之家收集整理的这篇文章主要介绍了跨域问题其他解决方案前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Nginx配置

server {  
        location / {  
            if ($request_method = 'OPTIONS') {  
              add_header 'Access-Control-Allow-Origin' '*';  
              add_header 'Access-Control-Allow-Credentials' 'true';  
              add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS';  
              add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';  
             # add_header 'Access-Control-Max-Age' 1728000;  
              add_header 'Content-Type' 'text/plain charset=UTF-8';  
              add_header 'Content-Length' 0;  
              return 200;  
            }  
    }

tomcat配置

引入下载cors-filter-1.7.jar,java-property-utils-1.9.jar这两个库文件,放到lib目录下
下载地址http://search.maven.org

  
    CORS  
    com.thetransactioncompany.cors.CORSFilter  
      
     cors.allowOrigin  
        *  
      
      
     cors.supportedMethods  
        GET,HEAD,PUT,DELETE  
      
      
     cors.supportedHeaders  
        Accept,Origin,Content-Type,Last-Modified  
      
      
        cors.exposedHeaders  
        Set-Cookie  
      
      
        cors.supportsCredentials  
        true  
      
  
  
    CORS  
    /*  
  

猜你在找的程序笔记相关文章