与$ Resource使用withCredential

Ale*_*Grs 6 javascript angularjs angular-http

我想在导航器中使用带有cookie的资源.

使用$ http非常简单,因为我只需将withCredential设置为true:

$http({
    method: 'POST',
    url: url,
    data: user,
    withCredentials: true
});
Run Code Online (Sandbox Code Playgroud)

但是对于$ resource,我没有找到解决方案来点同样的...我在github上看到了关于这一点的讨论,但我认为对于所有请求,对于true的设置为true是不正常的.你知道怎么做吗?

Muh*_*eda 16

要更改$http(因此为$ resource)的默认设置,您需要更改$httpProvider.

withCredentials全局设置如下:

angular.module('YOUR_APP')
    .config(function($httpProvider) {
        $httpProvider.defaults.withCredentials = true;
    });
Run Code Online (Sandbox Code Playgroud)


zs2*_*020 6

$ resource模块中的配置withCredentials在AngularJS 1.1.2+中可用,您可以获得新版本并尝试一下.