Setting request cookies angular2 http post request

前端 未结 1 1961
忘掉有多难
忘掉有多难 2020-12-31 23:31

I have a login service that performs an http request (to a php backend server) and returns a cookie. After login this cookie is needs to be used in all further requests done

相关标签:
1条回答
  • 2020-12-31 23:50

    Try this for the login:

    (...)
    return this.http.post("http://localhost/request.php", "data="+ jsonRequest,
        { withCredentials: true,
            headers: new Headers({
            'Content-Type': 'application/x-www-form-urlencoded'
        })
        }).map(...)
    

    And the other requests:

    (...)
    return this.http.post("http://localhost/request.php", "data="+ jsonRequest,
                          {withCredentials: true}).map(...)
    

    Basically, just use withCredentials option set to true.

    0 讨论(0)
提交回复
热议问题