0
我有一個在服務器端(Rest服務)創建的cookie。 下面是它創建的cookie休息服務:無法在服務器端(Jersey)創建的角度js獲取cookie
@Path("token")
public class AuthService {
@POST
@Produces(MediaType.APPLICATION_JSON)
public Response generateToken(@Context HttpServletRequest httpServletRequest) {
//some code to get serializedJwt and xsrftoken. path is "/" and domain is "http://localhost"
Cookie jwtCookie = new Cookie("jwt", serializedJwt, path, domain);
Cookie xsrfCookie = new Cookie("X-XSRF-TOKEN", xsrfToken, path, domain);
NewCookie newJwtCookie = new NewCookie(jwtCookie, null, maxAge, false);
NewCookie newXsrfCookie = new NewCookie(xsrfCookie, null, maxAge, false);
return Response.status(SUCCESSFUL_REQUEST)
.header(ERROR_HEADER_NAME, SUCCESS)
.header("SET-COOKIE", newJwtCookie.toString()+" ; HttpOnly")
.header("SET-COOKIE", newXsrfCookie.toString())
.entity(MAPPER.writeValueAsString(responseBody)).build();
}
}
我現在想以檢索從角JS(v1.4.6)應用此cookie。
console.log($cookies.get("X-XSRF-TOKEN")); //prints undefined
$cookies.put('abc',"kishore"); //just for testing purpose
console.log($cookies.get("abc")); //this prints kishore
console.log(document.cookie); //this prints "abc=kishore"
注: 僅Http是X-XSRF-TOKEN假。
那麼您可以通過瀏覽器接收到HTTP響應頭? – Michael