gpt4 book ai didi

angular - 如何使用基于 cookie 的 session 和 CSRF header 配置 JSData?

转载 作者:行者123 更新时间:2023-12-05 05:17:14 24 4
gpt4 key购买 nike

我需要设置我的 JSData 配置以传递基于 cookie 的 session 身份验证的信息以及 CSRF header 。

最佳答案

实例化 HttpAdapter 时,使用以下设置 withCredentials ( read more ) 和 CSRF header (下面的示例设置 X-CSRFToken header ,但这是特定于服务器端框架的;在其他情况下可能是其他内容。

const adapter = new HttpAdapter({
...
httpConfig: {
withCredentials: true // send cookie-based session credentials
},
...
beforeHTTP: function(config, opts) {
...
config.headers || (config.headers = {});
config.headers['X-CSRFToken'] = token;
...
return HttpAdapter.prototype.beforeHTTP.call(this, config, opts);
}
})

获取 token 的值可以通过不同的方式完成,例如basic version , Angular 2+ version

关于angular - 如何使用基于 cookie 的 session 和 CSRF header 配置 JSData?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49541460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com