加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 创业 > C语言 > 正文

跨域问题其他解决方案

发布时间:2020-12-15 00:36:45 所属栏目:C语言 来源:网络整理
导读: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

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  
    /*  
  

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读