gpt4 book ai didi

angularjs - Ionic 应用程序的跨源资源共享问题

转载 作者:行者123 更新时间:2023-11-28 23:30:11 25 4
gpt4 key购买 nike

所以我正在尝试从我的 ionic 应用程序向另一个在 tomcat apache 服务上运行的应用程序进行 http 调用,但是我认为由于 CORS 问题,调用没有成功。我按照本网站上的说明进行操作 http://blog.ionic.io/handling-cors-issues-in-ionic/没有运气。我在 http://localhost/platform/ 上运行 tomcat apache 应用程序和本地主机上的 ionic 应用程序:8100 我将其添加到我的 ionic.project 中:

{
"name": "mobile",
"app_id": "",
"proxies": [
{
"path": "/platform",
"proxyUrl": "http://localhost/platform/",
}
]
}

也将此添加到我的 gulpfile.js 中:

gulp.task('install', ['git-check'], function() {
return bower.commands.install()
.on('log', function(data) {
gutil.log('bower', gutil.colors.cyan(data.id), data.message);
});
});

gulp.task('git-check', function(done) {
if (!sh.which('git')) {
console.log(
' ' + gutil.colors.red('Git is not installed.'),
'\n Git, the version control system, is required to download Ionic.',
'\n Download git here:', gutil.colors.cyan('http://git-scm.com/downloads') + '.',
'\n Once git is installed, run \'' + gutil.colors.cyan('gulp install') + '\' again.'
);
process.exit(1);
}
done();
});

我还将这一行添加到我的 app.js 中:

.constant('appBaseUrl', 'http://localhost:8100/platform')

这是我进行的 http 调用:

$http({
method: 'post',
url: appBaseUrl + '/j_spring_security_check',
params: {
'j_username': credentails.username,
'j_password': credentails.password
}
})

但是,控制台无法获取 loginsuccess.json,这是对 tomcat 上后端服务器身份验证成功的响应。这是控制台上的响应 http://s16.postimg.org/m2ua3kqc5/console.png

我花了一整天的时间尝试完成这项工作,但运气不佳。顺便说一下 http://localhost/platform/ 的代理和代理通行证规范在 apache 文件夹中的 httpd.conf 文件中定义。

最佳答案

这可能是您的端口号不同,我敢打赌这会因浏览器而异。您正在测试的当前浏览器可能会将 localhost:80 和 localhost:9000 视为关于 CORS 的两个不同域。尝试根据上下文区分应用程序。这样浏览器就可以确定所有请求都来自同一个父上下文。

parent 语境

http://localhost/platform/

子上下文( ionic )

http://localhost/platform/ionic

关于angularjs - Ionic 应用程序的跨源资源共享问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31445230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com