【问题标题】:SessionId keeps changing in every curl request in Spring Boot ApplicationSessionId 在 Spring Boot Application 中的每个 curl 请求中不断变化
【发布时间】:2021-09-11 07:57:40
【问题描述】:

我有以下返回 SessionId 的 RestController:

@GetMapping(value = "/api/sessionid")
public @ResponseBody String getSessionId() {
    return RequestContextHolder.currentRequestAttributes().getSessionId();
}

当我使用 PostmanChrome 浏览器 时,它会在每个请求上返回相同的 SessionId。但是当我使用 CURL 来获取 SessionId 时,它会在每个请求上返回一个 不同 SessionId。

为什么我使用 CURL 时 SessionId 会改变?

【问题讨论】:

  • 因为你没有发送会话cookie,如果你使用浏览器默认发送。

标签: spring-boot rest session curl spring-security


【解决方案1】:

当您使用 Chrome 向服务器发送请求时:服务器使用 cookie 作为会话跟踪机制来识别您的会话。 当您使用 CURL 时:没有会话跟踪机制,这就是服务器为每个请求创建一个新会话的原因。

您可以在此处阅读有关会话跟踪的更多信息:https://javapapers.com/servlet/explain-the-methods-used-for-session-tracking/

【讨论】:

    猜你喜欢
    • 2018-06-05
    • 2010-09-21
    • 2017-02-24
    • 1970-01-01
    • 1970-01-01
    • 2014-09-16
    • 2020-02-17
    • 2022-01-23
    • 2021-04-05
    相关资源
    最近更新 更多