admin管理员组文章数量:1192948
I want to use resource with a cookie set in the navigator.
With $http it is really easy, as I only need to set withCredential to true:
$http({
method: 'POST',
url: url,
data: user,
withCredentials: true
});
But for $resource, I didn't find a solution to dot the same... I saw a discussion on github about that but I think that settings withCredential to true for all requests is not okay. Do you have an idea about how to do it?
I want to use resource with a cookie set in the navigator.
With $http it is really easy, as I only need to set withCredential to true:
$http({
method: 'POST',
url: url,
data: user,
withCredentials: true
});
But for $resource, I didn't find a solution to dot the same... I saw a discussion on github about that but I think that settings withCredential to true for all requests is not okay. Do you have an idea about how to do it?
Share Improve this question edited Aug 9, 2017 at 15:38 Cœur 38.7k26 gold badges202 silver badges277 bronze badges asked Sep 1, 2013 at 19:30 Alex GrsAlex Grs 3,3015 gold badges41 silver badges58 bronze badges3 Answers
Reset to default 19To change the default settings of $http
(hence $resource
), you need to alter $httpProvider
.
Set withCredentials
globally like that:
angular.module('YOUR_APP')
.config(function($httpProvider) {
$httpProvider.defaults.withCredentials = true;
});
The config withCredentials
in $resource module is available in AngularJS 1.1.2+, you can get the new version and give it a try.
You can set it the flag globally with:
$http.defaults.withCredentials = true;
This will affect all requests from the $resource
module as well as the $http
module.
本文标签: javascriptUse withCredential with resourceStack Overflow
版权声明:本文标题:javascript - Use withCredential with $resource - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738468613a2088449.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论