【发布时间】:2018-08-19 19:13:29
【问题描述】:
我无法以任何浏览器接受 302 响应的方式从服务器端为 localhost 设置 cookie。当浏览器收到响应时,我可以看到下一个标题(其中一些):
Request URL: https://non-localhost-server-url
Request Method: GET
Status Code: 302 Found
Referrer Policy: no-referrer-when-downgrade
Response Headers
view source
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 0
location: http://127.0.0.1:8081/
Server: nginx
set-cookie: token=XXXXXXXXX; Version=1; Domain=127.0.0.1; Path=/
Request Headers
view source
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,uk;q=0.8,ru;q=0.7
Connection: keep-alive
Referer: http://127.0.0.1:8081/login
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
但浏览器不保存 cookie(我在 Chrome 的内容设置中检查它)。我尝试将 cookie 的域设置为 localhost 而根本没有设置域,但这没有帮助。 也许应该存在一些额外的标题?提前致谢。
【问题讨论】:
-
127.0.0.1不是 "localhost"