简体   繁体   English

在请求angularjs http get内发送cookie

[英]send cookie inside request angularjs http get

I have the following http get , that I would like to send a cookie with a language on the request, but turns out with $cookieStore, it sends the cookie outside of the request 我有以下http get,我想在请求中发送一种语言的cookie,但结果是$ cookieStore,它在请求之外发送了cookie

$cookieStore.put("language", "pt-PT");

I tried this as well 我也尝试过

var myObject = {
    headers: { 'language': 'pt-PT'}
}//ignored

return $http.get(comm.endpoints.getEntityFinancialPosition, myObject );

In my debug I can see that this just created a new header that is not sent inside the cookie 在我的调试中,我可以看到这只是创建了一个新的标头,该标头未在Cookie内发送 在此处输入图片说明

The scope of the cookie is restricted with the domain option. cookie的范围受domain选项限制。 If page domain is different than API domain cookie will not be sent when making a request. 如果页面域不同于API域,则在发出请求时将不发送cookie。 To fix that set the right domain for the cookie $cookieStore.put("language", "pt-PT", {domain: 'requestdomain.com'}) . 要解决该问题,请为cookie $cookieStore.put("language", "pt-PT", {domain: 'requestdomain.com'})设置正确的域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM