How to access Response cookies in angular2?

Discussão em 'Angular' iniciado por Caius, Dezembro 19, 2024.

  1. Caius

    Caius Guest

    I'm trying to access this cookies (the response ones): [​IMG]

    When I open the request in the chrome debug tools in the network section I can clearly see that the cookies are present, but how can I access those values from my code? I've never worked with cookies before and I don't know what to do to "extract" them... I'm working on a Ionic2 project using Http.

    I've read that the allowCredentials: true header has to be sent but that didn't work...

    Here's the request/response details:


    [​IMG]

    Here's the service:


    public callLogin(service_guid: string, pos_guid: string, login_data: Object) {

    return this.http.post(
    this.url + service_guid + "/" + pos_guid + "/ack",
    login_data,
    {withCredentials: true}
    )
    .map(response => response.headers);
    }

    And the caller:


    this.__posService.callLogin(login_data.service_guid, login_data.pos_guid, {"password": data.password})
    .subscribe(
    res => {
    console.log("Success:");
    console.log(res.get("apsession"); // this returns undefined
    },
    err => {
    console.log("Error:");
    }
    );


    When I try to access the cookie from the header it returns undefined. What am I doing wrong here?

    Continue reading...

Compartilhe esta Página