大家好,我正在开发 Angularjs 网络应用程序。我正在使用 API 获取数据。登录成功后,我将在 cookie(响应 header )中获取一些数据。在接下来的后续 http 调用中,我需要将 cookie 数据发送回 api。下面是响应 header 的快照。
下面是我的示例 $http 调用。
var req = {
method: 'POST',
url: savepersonaldetailsurl,
headers: {
RequestedPlatform: "Web",
RequestedLanguage: cookiePreferredLanguage
},
data: {
LoginId: LoginID
}
$http(req).then(function (response) {
//do something here
}, function (error) {
toastr.error($filter('translate')('Error Occured'));
});
在每个 http 调用中,我想在 header 中发送 cookie。我可以知道如何在 angularjs 中完成吗?任何帮助,将不胜感激。谢谢。
最佳答案
Cookie 的一个特点是它们会随每个请求一起发送到服务器。确保发出请求的域与设置它的域相同或子域。
The cookie is usually stored by the browser, and then the cookie is sent with requests made to the same server inside a Cookie HTTP header - https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies
关于javascript - 如何在angularjs的每个请求头中发送cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45303116/