Small Program Development "3": Reasons for the small program request failure to use the session and solutions, "3" session
I mentioned in the previous applet development "2" that to maintain the status on the server, the client must return a sessionid to the client when requesting the server for the first time, which is saved locally by the client, the sessionid is included in the header in the next request and written to the cookie field. However, in the recent request, even if the sessionid in the header still cannot get the same session, Baidu finally found a pitfall (I don't know why I want to do this. the request API has been modified. The request initiated by the applet does not directly request Our backend server, but is sent to Our backend server through the server first, since requests are sent to our server through the server, our server will not be able to identify the request initiator. Therefore, sessions cannot be used in Background Development of applets.
Since the session cannot be used, I can only use other methods to replace the good way for my web backend program. I used redis to replace the session function. When the client sends a request to the backend server, a random string is generated as the key, which was originally placed in the session content, generally, the user information is stored in redis as the value, and then the key is returned to the client. The client stores the key locally and carries the key as a parameter in the next request, in this way, when the backend server receives the key, it can find the value corresponding to the key from redis to achieve the effect of replacing the session. redis can also set the key expiration time.