Android Django、Ionic、$http和空响应

Android Django、Ionic、$http和空响应,android,angularjs,django,ionic,Android,Angularjs,Django,Ionic,我有一个带有csrf视图的django设置,用于将csrf令牌设置为请求者cookie,如下所示: @ensure_csrf_cookie def csrf_view(request): return HttpResponse('', content_type="text/plain") .factory('CSRF', function ($q, $cookies, $http) { return { get: function () {

我有一个带有csrf视图的django设置,用于将csrf令牌设置为请求者cookie,如下所示:

@ensure_csrf_cookie
def csrf_view(request):
    return HttpResponse('', content_type="text/plain")
.factory('CSRF', function ($q, $cookies, $http) {
    return {
        get: function () {
            var q = $q.defer();
            $http.get(csrfEndpoint, {
                withCredentials: true,
                responseType: "text",
                transformResponse: undefined
            })
                .success(function (data, status, headers, config) {
                    q.resolve($cookies['csrftoken']);
                })
                .error(function (data, status, headers, config) {
                    console.log('data: ' + data);  // data is null
                    console.log('status: ' + status);  // status is 0
                    console.log('headers: ' + dictToString(headers()));
                    console.log('config: ' + dictToString(config));
                })
            ;
            return q.promise;
        }
    }
})
我将djangoc cors headers和cors_ORIGIN_ALLOW_都设置为True,但从android emulator,当我使用$http.get向其发送get请求时,响应是错误的,其中数据为null,状态为0。我错过什么了吗

角度服务如下所示:

@ensure_csrf_cookie
def csrf_view(request):
    return HttpResponse('', content_type="text/plain")
.factory('CSRF', function ($q, $cookies, $http) {
    return {
        get: function () {
            var q = $q.defer();
            $http.get(csrfEndpoint, {
                withCredentials: true,
                responseType: "text",
                transformResponse: undefined
            })
                .success(function (data, status, headers, config) {
                    q.resolve($cookies['csrftoken']);
                })
                .error(function (data, status, headers, config) {
                    console.log('data: ' + data);  // data is null
                    console.log('status: ' + status);  // status is 0
                    console.log('headers: ' + dictToString(headers()));
                    console.log('config: ' + dictToString(config));
                })
            ;
            return q.promise;
        }
    }
})

问题是缺少配置。这种配置实际上是:


CORS_ALLOW_CREDENTIALS=True

首先尝试检查cordova版本

cordova -v
如果版本>4.3

尝试添加

ionic plugin add cordova-plugin-whitelist
然后加上

<access origin="*"/>


在android emulator中测试config.xml文件