Angular 2: Get Authorization header

前端 未结 3 1661
春和景丽
春和景丽 2020-12-16 02:45

in my App (Angular 2 / Ionic 2) I implemented my own login/authentication. Basically it works like this: On login, username and password is being validated by the PHP backen

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-16 03:04

    This answer helped me : link

    It shows how to add it in the backend and how use it in the frontend

    Java backend:

    public void methodJava(HttpServletResponse response){
    ...
    response.addHeader("access-control-expose-headers", "Authorization");
    }
    

    And access the header on angular like this:

    return this.http
        .get()
        .map(res => console.log("cookie: " + res.headers.get("Authorization") )
    }
    

提交回复
热议问题