【问题标题】:Rest-assured sends cookies with wrong expires date format?放心发送过期日期格式错误的 cookie?
【发布时间】:2018-09-04 07:53:43
【问题描述】:

根据 cookie 规范,cookie 的 expires 属性应采用 Expires=Wed, 09 Jun 2021 10:18:14 GMT 的格式。

我正在使用放心发送带有请求的 cookie,但到期日期的格式如下:Expires=9/4/18 12:03 PM

我正在使用 rest-assured 的 Cookie.Builder.setExpiryDate() 创建 cookie,它只接受一个 java Date 对象作为输入。

我有什么办法可以敦促放心更改到期日期的格式以符合 cookie 规范?

【问题讨论】:

    标签: java cookies rest-assured


    【解决方案1】:

    没有。因为他们使用以下代码

    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
                    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
                    builder.append(COOKIE_ATTRIBUTE_SEPARATOR).append(EXPIRES).append(EQUALS).append(simpleDateFormat.format(expiryDate));
    

    那么,你会得到的和这个是等价的

        Date d1 = new Date();
        System.out.println(d1);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
        System.out.println(simpleDateFormat.format(d1));
    

    输出类似于“2019 年 7 月 10 日,下午 5:50”。

    您可以获取值,然后在结束时进行格式化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多