Spring :Inserting cookies in a REST call response

后端 未结 5 1508
萌比男神i
萌比男神i 2020-12-16 17:45

I am implementing REST API endpoints using spring mvc. I am trying to send back a HTTP response with a cookie value. This is the equivalent of what I need

5条回答
  •  我在风中等你
    2020-12-16 18:25

    You can use Spring API for Cookie: org.springframework.http.HttpCookie:

    HttpCookie cookie = ResponseCookie.from("heroku-nav-data", nav_data)
            .path("/")
            .build();
    return ResponseEntity.ok()
            .header(HttpHeaders.SET_COOKIE, cookie.toString())
            .body(id);
    

提交回复
热议问题