AngularJS: $httpProvider.defaults.withCredentials = true;

Requests_with_credentials

$httpProvider.defaults.withCredentials = true;

Whether to set the withCredentials flag on the XHR(XMLHttpRequest) object.

If you use the standard $http service to access remote APIs, it will Just Work as long as the server is configured to allow requests from your domain and you don’t need to store cookies.

But for many applications, we also need to set and store cookie information for things like logins. By default this is not allowed in most browsers and you’ll be smashing your head wondering why the cookie information isn’t being saved!

Enter: withCredentials. withCredentials is a flag set on a low-level XMLHttpRequest (AJAX) object, but in Angular we can configure our $http requests to set this flag for everything by doing:

angular.module('myApp')
.config(['$httpProvider', function($httpProvider) {
  $httpProvider.defaults.withCredentials = true;
}])
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wwq518/article/details/52374143
文章标签: angular xmlhttprequest
个人分类: 安全
上一篇AngularJS: directive
下一篇cascade operation (级联操作)
博主设置当前文章不允许评论。

没有更多推荐了,返回首页

关闭
关闭