【发布时间】:2015-09-19 19:16:46
【问题描述】:
我正在 Cordova 中创建 android 应用程序,女巫使用 AngularJs 使用 REST 服务, 我首先通过这个 URL 在浏览器上测试这个应用程序 file:///C:/Users/Users/MyApps/project/platforms/android/assets/www/index.html#/demande/list 但仍然给出此错误:
跨域请求被阻止:同源策略不允许读取远程资源 http://10.0.2.2:8080/springrestprojet/rest/demande。原因:CORS 请求失败。
我正在使用 CORS 过滤器来启用访问。 这是我的 service.js 代码:
'use strict';
angular.module('workflowService', ['ngResource']).
factory('Demande', function ($resource) {
return $resource('http://10.0.2.2:8080\:8080/springrestprojet/rest/demande/:id', {}, {
'save': {method:'PUT',
headers: {'Content-Type': 'application/json',
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Methods' : 'POST, GET, OPTIONS, PUT',
'Access-Control-Request-Method':'*',
'Access-Control-Allow-Headers':'*',
'Accept': 'application/json'}},
});
});
有什么帮助吗? 非常感谢。
【问题讨论】:
-
如果您想从您的应用程序发出跨域请求,请考虑在您的 config.xml 文件中添加
-
我做到了,但还是不行:(
标签: android angularjs cordova rest cors