【问题标题】:angularJS $resource with basic authentiction and JSONP具有基本身份验证和 JSONP 的 angularJS $resource
【发布时间】:2013-11-16 19:27:36
【问题描述】:

我是 angularJS 的新手,我正在使用 $resource 来访问 RestAPI。 angularJS 中的 JSONP 可以在 $resource 中进行身份验证吗?

【问题讨论】:

  • 如果你的认证需要一个header,你可以这样设置。 $http.defaults.headers.common['Authorization'] = ...

标签: angularjs jsonp


【解决方案1】:

是的,有可能。

您应该配置 httpRequests 的标头以包含 withCredentials 之一。

可以这样做:

var myApp = angular.module('myApp', []);

myApp.config(['$httpProvider', function($httpProvider) {
    // Default with credential to all methods
    $httpProvider.defaults.withCredentials = true;
}]);

有关标题的更多信息,请参阅docs。

【讨论】:

    猜你喜欢
    • 2015-09-09
    • 1970-01-01
    • 1970-01-01
    • 2020-06-15
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    • 2015-03-13
    • 1970-01-01
    相关资源
    最近更新 更多