在Phonegap应用程序中使用AuthInterceptor

时间:2015-07-26 18:28:38

标签: android angularjs cordova ionic-framework

我正在使用角度js和Ionic框架创建一个Phonegap应用程序。此应用程序使用http请求到服务器,我需要在每个http请求中注入一些参数。对于这个主题,我正在尝试使用一个名为authInterceptor的服务(我以前在Web应用程序中使用并且工作正常)必须拦截所有http请求,但此服务在移动设备中不起作用。我不确定我是否必须在手机应用程序中做一些不同的事情。这是我的服务:

.factory('AuthInterceptor', function($q, $location, AuthToken) {

var interceptorFactory = {};
// this will happen on all HTTP requests
interceptorFactory.request = function(config) {

    if (condition) 
        //inject the parameters

    return config;
};

// happens on response errors
interceptorFactory.responseError = function(response) {

    // if our server returns a 403 forbidden response
    if (response.status == 403){

    }
    // return the errors from the server as a promise
    return $q.reject(response);
};

return interceptorFactory;

});

我希望有人可以帮我解决这个问题。非常感谢

0 个答案:

没有答案