Cookies on localhost with explicit domain

前端 未结 21 1792
[愿得一人]
[愿得一人] 2020-11-22 04:17

I must be missing some basic thing about cookies. On localhost, when I set a cookie on server side and specify the domain explicitly as localhost (or .localhost). t

21条回答
  •  [愿得一人]
    2020-11-22 04:54

    Tried all of the options above. What worked for me was:

    1. Make sure the request to server have withCredentials set to true. XMLHttpRequest from a different domain cannot set cookie values for their own domain unless withCredentials is set to true before making the request.
    2. Do not set Domain
    3. Set Path=/

    Resulting Set-Cookie header:

    Set-Cookie: session_token=74528588-7c48-4546-a3ae-4326e22449e5; Expires=Sun, 16 Aug 2020 04:40:42 GMT; Path=/
    

提交回复
热议问题