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

  • 相关阅读:
    通过HTTP发包工具了解HTTP协议
    Oracle之数据库安全
    SQL注入深入剖析
    apache中如何调用CGI脚本
    fastcgi php-cgi与php-fpm区别和之间的关系
    使用PHPExcel实现Excel文件的导入和导出(模板导出)
    学会数据库读写分离、分表分库
    框架Thinkphp5 简单的实现行为 钩子 Hook
    php文件下载
    PHP为JSON数据的API返回空数组或者空对象
  • 原文地址:https://www.cnblogs.com/aknife/p/14133202.html
Copyright © 2011-2022 走看看