无法读取后端发送的Cookie

问题描述 投票:0回答:1

我想使用JAX-WS和Jersey从后端发送一个简单的cookie到我的Angular Webclient,但是Chrome无法读取或设置cookie。

    @GET
    @Path("/cookie")
    @Produces(MediaType.TEXT_PLAIN)
    public Response getId(@CookieParam("session") String inp)
    {
        if (!keys.contains((inp))) {
            String cipher = randomize();
            keys.add(cipher);
            return Response.ok().cookie(new NewCookie("session", cipher)).build();
        }
        return Response.ok().build();
    }

这是我在后端执行的操作

private httpHeaders = new HttpHeaders()
        .set('Accept', 'text/plain')
        .set('Content-Type', 'text/plain');

    private options = {
        headers: this.httpHeaders
    };

  constructor(private httpClient: HttpClient) { }

  getId(){
    return this.httpClient.get(this.apiUrl+'session/cookie', this.options);
  }

这就是我在客户端进行管理的方式。

angular google-chrome jersey jax-ws
1个回答
0
投票

您需要subscribe到请求才能从API中获取值。

getId(){
    return this.httpClient.get(this.apiUrl+'session/cookie', 
          this.options).subscribe((token)=>{
           console.log(token)
      });
  }
© www.soinside.com 2019 - 2024. All rights reserved.