The front end cannot get the cookie set by the back end.

in the login screen: enter the account password to adjust the login interface to the backend, and the backend sets a cookie with the key of userInfo.
but here comes the problem.
in the vue project, in the locally launched server, the cookie, of userInfo is not available when you log in, but it is packaged and put on the test server, and the userInfo is available when you log in.
I would like to ask the bosses, what is the problem?
Boss, help me quickly, or the back end will fight me.

May.24,2021

the local server and the server of the interface are not in the same domain.
take a chestnut:
your local server is localhost:8080 , but the interface address you call is 192.168.0.111/api/login . When processing, the backend can only store cookie in the domain of the backend interface. That's 192.168.0.111 here.
this explains why you can't get it locally, but the goose can do it on the test server. Putting it on the test server is equivalent to web services running in the back-end server.
roughly means

solution

this is cross-domain. For security reasons, access is not available. Put your resources under the site of the interface address.


check the debugging of the login API


Open network to see if the response returns cookie . If you don't throw it directly in the face, it will be over.


the backend checks the storage location of the cookie?


first of all, it must be cross-domain. When cross-domain, some browsers do not carry cookie, by default. Therefore, in order to carry cookie, you need to set the withCrendetails property of xmlhttprequest. When using vue-resouce, set it as follows

  

have you solved it? I have the same problem now

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b40cac-2bcba.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b40cac-2bcba.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?