OkHttp 3 如何创建 cookie 域 从'.'开始



我正在使用okhttp 3创建cookie

var c1 = new Cookie.Builder()
.path("/")
.domain(".test.org")
.name("cookie-name")
.value("cookie-value")
.httpOnly().secure().build();

发生异常

"java.lang.IllegalArgumentException:意外域:.test.org"在里面.domain(".test.org")

我应该怎么做才能在cookie中创建域,第一个字符是".">

您可以省略前导.而不改变行为。来自RFC 6265:

如果属性值字符串的第一个字符是%x2E("."(:

Let cookie-domain be the attribute-value without the leading %x2E

最新更新