zoukankan      html  css  js  c++  java
  • 部分浏览器cookie无法传输cookie,谷歌51-66版本

    public void setCookieSameSite (HttpServletRequest request,HttpServletResponse response){
    String userAgent = request.getHeader("user-agent");
    Browser browser = UserAgent.parseUserAgentString(userAgent).getBrowser();
    if(browser)&&browser.getName().contains("Chrome"){
        Version version = browser.getVersion(userAgent);
        if(version.getMajorVersion()!=null){
            try{
                int majorVersion = Integer.parseInt(version.getMajorVersion());
        CookieSetUtil CookieSetUtil = new CookieSetUtil();
                // 如果是谷歌并且版本大于等于67,则重赛COOKIE
                if(majorVersion>=67){
                    List<String> cookieValues = CookieSetUtil.readCookieValues(request);
                    cookieValues.forEach(cookieValueStr -> {
                        CookieSerializer.CookieValue cookieValue = new CookieSerializer.CookieValue(request, response, cookieValueStr);
                        CookieSetUtil.writeCookieValue(cookieValue);
                    });
                }
            }catch (Exception e ){
                e.printStackTrace();
            }
        }
    }
    }
    <dependency>
             <groupId>eu.bitwalker</groupId>
             <artifactId>UserAgentUtils</artifactId>
             <version>1.21</version>
    </dependency>

    Browser browser = UserAgent.parseUserAgentString(userAgent).getBrowser(); 会出现异常

    在pom.xml中添加

     <plugin> 
           <artifactId>maven-assembly-plugin</artifactId> 
           <configuration> 
            <archive> 
             <manifest> 
              <mainClass>{pathToMainClass}</mainClass> 
             </manifest> 
            </archive> 
            <descriptorRefs> 
             <descriptorRef>jar-with-dependencies</descriptorRef> 
            </descriptorRefs> 
           </configuration> 
          </plugin> 

    CookieSetUtil类,就是复制的DefaultCookieSerializer类,主要用到了其中的2个方法:readCookieValueswriteCookieValue,并且我们需要修改SameSite的值:

    sb.append("; SameSite=").append("None");

    参考 https://blog.csdn.net/u014705309/article/details/104949474

      http://cn.voidcc.com/question/p-avvtahos-uu.html

  • 相关阅读:
    在单机Hadoop上面增加Slave
    两台机器添加信任关系
    JS Scoping and Hoisting
    SCSS(SASS、CSS)学习
    程序的内存情况
    delete-node-in-a-bst
    serialize-and-deserialize-bst
    Linux Shell脚本编程--curl命令详解
    iOS文件保存策略
    浅谈spring——spring MVC(十一)
  • 原文地址:https://www.cnblogs.com/aknife/p/14133202.html
Copyright © 2011-2022 走看看