2013-04-23 155 views
-1

我正在尝试使用POCO C++库学习C++网络编程。我将cookie添加到响应对象并返回给客户端。我可以通过firebug(使用Firefox)找到cookie值,但是通过js代码:alert(document.cookie),它无法显示该cookie信息,也无法将此cookie发送到服务器。无法将Cookie发送到服务器

Set-Cookie:name=testname; domain=testacshserver.com; path=/;expires=Tue, 23 Apr 2013 10:54:43 GMT; secure; HttpOnly 

当我使用IE9时也是如此。

+0

也许应该是未来的过期日期。 – rekire 2013-04-23 10:10:18

+4

它说'HttpOnly',所以你不应该能够通过JS访问它。 – Quentin 2013-04-23 10:14:41

+0

@Quentin Set-Cookie:name = testname;域= testacshserver.com;路径= /;到期= 2013年4月23日星期二12:05:10 GMT;安全 甚至HttpOnly没有设置,它是一样的 – 2013-04-23 11:08:38

回答

0

您需要省略仅通过HTTPS传输的部件secureHttpOnly,这使得Cookie无法从JavaScript访问Cookie。所以你只需要传输:

Set-Cookie:name=testname; domain=testacshserver.com; path=/;expires=Tue, 23 Apr 2013 10:54:43 GMT