Angular 6 does not add X-XSRF-TOKEN header to http request

前端 未结 7 2068
忘了有多久
忘了有多久 2020-12-02 21:06

I\'ve read the docs and all the related questions on SO, but still Angular\'s XSRF mechanism isn\'t working for me: in no way I can make a POST request with the X-XSRF-TOKEN

7条回答
  •  温柔的废话
    2020-12-02 21:25

    On my team, the problem was that we were using an absolute path instead of a relative path.

    So do not use an absolute path like:

    this.http.post("https://example.com/api/endpoint",data)
    

    Use

    this.http.post("api/endpoint",data)
    

    Or use

    this.http.post("//example.com/api/endpoint",data)
    

    This is because absolute paths are explicitly ignored by Angular code on HttpClientXsrfModule (see)

提交回复
热议问题