【发布时间】:2018-05-23 07:02:25
【问题描述】:
我正在尝试使用角度 5 将数据发布到服务器。 我的代码是:
createProfile(newProfile: NewProfile) {
this.http.post<NewProfile>(this.messageUrlPost, CreateFormData.createFormData(newProfile), {withCredentials: true, observe: 'response'}).subscribe(resp => {
// Read the result field from the JSON response.
console.log(resp.body);
});
}
为了能够执行请求,我需要通过身份验证 cookie。所以我使用:
withCredentials: true。但是由于某种原因,这在 Chrome 上不起作用(它拒绝发送 cookie)。在 Firefox 和 Edge 上它确实有效。
【问题讨论】:
-
您使用的是哪个版本的 Angular??
-
@Aravind ^5.0.3
-
你应该导入模块
HttpClientXsrfModule并设置配置 -
我这样配置它:` HttpClientXsrfModule.withOptions({ cookieName: '.AspNetCore.Identity.Application', headerName: 'Cookie' })` 但是它仍然不起作用。也许我没有正确配置它。没有很多关于如何使用
HttpClientXsrfModule的文档 -
您是否可以在 teamviewer 或远程连接中进行调试并帮助您解决此问题
标签: angular google-chrome authentication cookies