Set-Cookie header 未设置
Set-Cookie header is not set
我想从我的服务器收到一个 Set-Cookie header 的响应。我在服务器端使用 Jersey,spring-boot 和 Spring 安全性,在客户端使用 angular 2。我收到回复,但未设置 Set-Cookie header。它仅在元数据中:
{"statusType":"OK","entity":null,"entityType":null,"metadata":{"Set-Cookie":[{"name":"SomeName","value":"someId","version":1,"path":null,"domain":null,"comment":null,"maxAge":-1,"secure":false}]},"status":200}
但是没有"Set-Cookie"Header:
这是响应中的代码:
return Response.ok().cookie(new NewCookie("SomeName", "someId")).build();
方法“.header(..)”也不起作用。
像这样尝试
public ResponseEntity<?> resourceFunction(HttpServletResponse response) {
response.addCookie(new Cookie("SomeName", "someId"));
return ResponseEntity.ok().build();
}
ResponseEntity
、HttpServletResponse
和 Cookie
是从 javax.servlet.http.*
导入的
另一种选择:
public ResponseEntity<?> resourceFunction() {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add(HttpHeaders.SET_COOKIE, "SomeName=someId");
return new ResponseEntity(httpHeaders, HttpStatus.OK);
}
我想从我的服务器收到一个 Set-Cookie header 的响应。我在服务器端使用 Jersey,spring-boot 和 Spring 安全性,在客户端使用 angular 2。我收到回复,但未设置 Set-Cookie header。它仅在元数据中:
{"statusType":"OK","entity":null,"entityType":null,"metadata":{"Set-Cookie":[{"name":"SomeName","value":"someId","version":1,"path":null,"domain":null,"comment":null,"maxAge":-1,"secure":false}]},"status":200}
但是没有"Set-Cookie"Header:
这是响应中的代码:
return Response.ok().cookie(new NewCookie("SomeName", "someId")).build();
方法“.header(..)”也不起作用。
像这样尝试
public ResponseEntity<?> resourceFunction(HttpServletResponse response) {
response.addCookie(new Cookie("SomeName", "someId"));
return ResponseEntity.ok().build();
}
ResponseEntity
、HttpServletResponse
和 Cookie
是从 javax.servlet.http.*
另一种选择:
public ResponseEntity<?> resourceFunction() {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add(HttpHeaders.SET_COOKIE, "SomeName=someId");
return new ResponseEntity(httpHeaders, HttpStatus.OK);
}