离子请求仅在 android 上返回 404,在 Chrome 中它工作正常 [英] Ionic requests return 404 only on android, in Chrome it works fine

查看:28
本文介绍了离子请求仅在 android 上返回 404,在 Chrome 中它工作正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我从 ionic 克隆了教程应用程序仓库.我跑了

So, i have cloned the tutorial app repo from ionic. I ran

ionic start conference sidemenu

然后我添加了一个简单的 $http.get('myserver')(我也尝试过使用 ngResources).

and then i added a simple $http.get('myserver')(I tried with ngResources too).

它在 chrome 上运行良好,我取回了所有数据,但在 angular 上,我尝试执行的任何请求都只有空数据和 404 状态.

It worked perfect on chrome, I got all the data back but on angular i only got null data and 404 status on any request I tried to do.

注意:我尝试使用我的托管服务器和本地服务器.两者都在 Android 上失败.服务器是一个 node.js REST API.

Note: I tried with my hosted server and with a local one. Both fail on Android. Server is a node.js REST API.

控制台上没有打印任何内容,因此请求甚至没有到达服务器.

Nothing is printed on the console, so the request does not even get to the server.

有没有人遇到过或者可以告诉我如何调试使用 Ionic 构建的 Android 应用程序?

Has anyone experienced that or could tell me how can I debug Android apps built with Ionic?

编辑 1:我不知道你为什么需要它,但它在这里

EDIT 1: I don`t know why do you need it but here it is

$http.get('http://server.com/route').success(function (data) {
            //handle success
        }).error(function (data, status) {
            // handle error
        });

推荐答案

Cordova 4.0.0 有一些重大变化:

The thing is that there were some major changes in Cordova 4.0.0:

主要变化[...]- 现在通过插件提供白名单功能 (CB-7747)白名单已得到增强,更加安全和可配置框架现在支持设置内容安全策略(请参阅插件自述文件中的详细信息)您需要添加新的cordova-plugin-whitelist plugin 旧版白名单行为仍然存在可通过插件获得(虽然不推荐).

Major Changes [...] - Whitelist functionality is now provided via plugin (CB-7747) The whitelist has been enhanced to be more secure and configurable Setting of Content-Security-Policy is now supported by the framework (see details in plugin readme) You will need to add the new cordova-plugin-whitelist plugin Legacy whitelist behaviour is still available via plugin (although not recommended).

所以我安装了Cordova 白名单插件.并添加了

So I installed the Cordova Whitelist plugin. And added

<allow-navigation href="http://*/*" />

在我的 config.xml 文件中.

这篇关于离子请求仅在 android 上返回 404,在 Chrome 中它工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆