OkHttp 3 如何创建以“.”开头的 cookie 域

发布于 2025-01-11 07:18:22 字数 360 浏览 2 评论 0原文

我正在使用 okhttp 3 create 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 中创建域,第一个字符是“.”

I am using okhttp 3 create cookie

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

An exception occurred

"java.lang.IllegalArgumentException:unexpected domain: .test.org" in
.domain(".test.org")

what should I do to create the domain in the cookie is the first character is '.'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久而酒知 2025-01-18 07:18:22

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

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

 让 cookie-domain 为不带前导 %x2E 的属性值

You can omit the leading . without a change in behavior. From RFC 6265:

If the first character of the attribute-value string is %x2E ("."):

  Let cookie-domain be the attribute-value without the leading %x2E
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文