Set-Cookie标头未在Internet Explorer中设置Cookie [英] Set-Cookie header does not set cookie in Internet Explorer

查看:328
本文介绍了Set-Cookie标头未在Internet Explorer中设置Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Set-Cookie标头设置cookie服务器端.

I'm trying to set a cookie server-side using the Set-Cookie header.

使用球衣将cookie设置在服务器端,如下所示:

Using jersey the cookie is set server side like this:

NewCookie cookie  = new NewCookie("token", tokenValue, "/", "", 1, "", 3600, new Date(System.currentTimeMillis() + 3600000), false, false);
return Response.ok()
                .cookie(cookie)
                .build();

我在Chrome浏览器中的响应标题如下:

My response header in Chrome looks like this:

当我尝试向服务器发送另一个请求时,要检查cookie是否已发回,一切都会按预期进行.请求标头如下所示:

When I try to send another request to the server, to check if the cookie is send back, everything works as expected. The request header looks like this:

Firefox和Opera浏览器也显示相同的行为.虽然,当我尝试使用Internet Explorer时,还有另一个故事...

Firefox and Opera browsers also show the same behavior. Although, when I try Internet Explorer, there's another story...

第一个请求的响应头:

Response headers of the first request:

第二个请求的标题:

Headers of the second request:

基本上没有请求标头,并且未设置cookie ... 设置Cookie时,我做错什么了吗?我已经尝试了其他类似问题的各种解决方案,但似乎无济于事...

Basically there are no request headers, and the cookie is not set... Am I doing something wrong, when I set the cookie? I have tried various solutions from other similar questions, but nothing seems to work...

通过禁用保护模式更改了IE Internet选项,并允许所有cookie,但仍然没有任何内容...

Changed the IE Internet options by disabling protected mode and allowed all cookies, but still nothing...

在不同的计算机上尝试,结果不一.在某些计算机中,它可以正常工作,而在某些计算机中,则不能.我缺少Internet Explorer上的某些设置.虽然,无论我如何尝试,都无法在localhost ...

Trying it on different computers, I get mixed results. In some computers it works properly, and in some it doesn't. There must be some settings on the Internet Explorer that I am missing. Although, no matter what I try, I cannot get it to work on localhost...

解决方案

显然,正如dabaicai所说,不应有任何空的属性值字段.当我创建Cookie时,domaincomment atrribute的值为空:

Apparently, as dabaicai commented there should not be any empty attribute-value fileds. when I created my cookie the domain and comment atrribute had empty values:

NewCookie cookie  = new NewCookie("token", tokenValue, "/", "", 1, "", 3600, new Date(System.currentTimeMillis() + 3600000), false, false);

我将其更改为:

NewCookie cookie  = new NewCookie("token", tokenValue, "/", httpServletRequest.getServerName(), 1, "no-comment", 3600, new Date(System.currentTimeMillis() + 3600000), false, false);

现在,一切也都可以在Internet Explorer中正常工作!

And now everything works as expected in Internet Explorer too!

推荐答案

我认为由于域localhost,您可以尝试使用127.0.0.1访问URL,然后查看结果.

I think because of the domain localhost,you can try visit the URL with 127.0.0.1,and then see the result.

这篇关于Set-Cookie标头未在Internet Explorer中设置Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆