O
O
Oleg Voitenko2018-04-27 14:51:57
Angular
Oleg Voitenko, 2018-04-27 14:51:57

How to read Cookies in back response in Angular 4?

From the front to Angular 4 I make a request to the backend, they receive Respons with a cookie.
The code:

login(somevar: string, somevartwo: string) {
      return this.http.post('http://somebackand.com/login',
          {username: username, password: password},
          {
              observe: "response",
              headers: new HttpHeaders({
                  "Access-Control-Allow-Origin": "*",
                  "Access-Control-Allow-Methods": "POST,GET,OPTIONS",
                  "Access-Control-Allow-Headers": "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token,Access-Control-Allow-Origin, Authorization, Access-Control-Allow-Origin",
                  "crossDomain": "true",
                  "Access-Control-Allow-Credentials": "true"
              })
          })

          .map(response => {
              console.log(response.headers.get("Set-Cookie"));
          });
  }

In the console I read - undefined
In the browser, the cookie is visible in the incoming response.
How to correctly map Set-Cookie in the response header?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question