Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ionic运行android时未找到ionic错误404_Android_Node.js_Cors_Ionic_Sails.js - Fatal编程技术网

ionic运行android时未找到ionic错误404

ionic运行android时未找到ionic错误404,android,node.js,cors,ionic,sails.js,Android,Node.js,Cors,Ionic,Sails.js,我有一个ionic应用程序,当我向我的本地主机发出POST orGET请求时,它与ionic serve配合得很好;当我制作ionic uild android,然后运行ionic android时,它与bt配合得很好。我总是收到一个404 POST not found, 我几乎什么都试过了。 我已经添加了插件白名单并将其放入我的config.xml中 <content src="index.html"/> <access origin="*"/> <a

我有一个ionic应用程序,当我向我的本地主机发出POST orGET请求时,它与ionic serve配合得很好;当我制作ionic uild android,然后运行ionic android时,它与bt配合得很好。我总是收到一个404 POST not found, 我几乎什么都试过了。 我已经添加了插件白名单并将其放入我的config.xml中

  <content src="index.html"/>
  <access origin="*"/>
  <allow-intent href="*"/>
  <allow-navigation href="*"/>
})

在app.js的开头,我有这个配置

  angular
.module('frontend', [
  'ionic', 'ionic.service.core',
  'frontend.core',
  'ionic.service.analytics',
  //'cacheapp',
  //'cachemodule',
  'ionic-cache-src',
  'formlyIonic',
  'pascalprecht.translate',
  'angularMoment',
  'ionic.components',
  'ngFacebook',
  'translate.app',
  'translate.form',
  'angular-cache',
  'ngCordova',
  'gettext',
  'module.user',
  'module.gallery'
])
.constant('AccessLevels',{
      anon: 0,
      user: 1,
      admin: 2
})
.constant('BackendConfig',{
  url: "http://api-test-dev.com:1337",
  //url: "http://ip_of_my_phone:1337"
  //url: "10.0.2.2"
  //url: "10.0.2.2:1337"
  //url:"http://ip_of_my_phone"
  //url:"http://ip_of_my_wifi"
  //url:"http://ip_of_my_wifi:1337"
})
注释URL是我尝试的所有选项:我使用ifconfig获得它们,当我的手机出现这种情况时,我禁用了计算机上的wifi,并使用了手机的usb连接(因此ifconfig中的ip是usb0)。我还在app.js中使用端口转发尝试了url“”chrome://inspect/#devices (通过向我的设备的端口1337分配本地主机:我的计算机的1337) . 对于我的文件app.js中列出的URL,我禁用了端口转发

但所有配置都会给出错误POST 404 not found


有什么想法吗?

我想我以前遇到过这个问题

原因是当您运行
ionic-serve
ionic-run-android-l
时,它运行的是从您的计算机托管的代码(www文件夹),而不是设备。因此,它可以直接访问
localhost
。但是,当您构建它并在实际设备上运行时,其中没有托管本地主机,然后出现
404notfound

这就是我解决问题的方法(仅适用于相同的Wi-fi网络)

  • 获取计算机的LAN/Wi-fi IPv4(例如:
    192.168.1.2
  • 将中的url替换为您的计算机IP
  • 在末尾添加端口。(例如:
    http://192.168.1.2:1337
  • 运行
    ionic运行android

感谢nam的快速回答,但我也尝试了此解决方案->查找app.js文件。我尝试了所有已注释的url。您是否尝试在设备内打开Chrome/Browser并导航到localhost链接?如果我转到ifconfig提供的url,我在apache页面上,该页面会打印“it Works”,如果我转到htttp://ip_given_for_the_wifi:1337 当帆船航行时,我得到了一张空白页(正常,因为我在服务器上没有显示任何内容)。其他ip或具有不同主机的同一ip给出了err_connection_densed。因此它似乎可以工作,但在应用程序中我仍然无法进行REST。这里是我得到的确切错误:POST 404(未找到)angular.js:10722 Object{data:“,状态:404,标题:函数,配置:对象,状态文本:“未找到”}我为您提供了更多选项:1/尝试将所有服务器代码托管在真正的服务器中,并使用该服务器ip再次执行此操作。2/检查android项目文件夹中AndroidManifest.xml中的internet权限。3/将您的url替换为此api端点,以检查您的应用程序是否可以连接到外部资源。让我知道其中是否有任何结果t@moubert
module.exports.cors = {
/***************************************************************************
 *                                                                          *
 * Allow CORS on all routes by default? If not, you must enable CORS on a   *
 * per-route basis by either adding a "cors" configuration object to the    *
 * route config, or setting "cors:true" in the route config to use the      *
 * default settings below.                                                  *
 *                                                                          *
 ***************************************************************************/
allRoutes: true,

/***************************************************************************
 *                                                                          *
 * Which domains which are allowed CORS access? This can be a               *
 * comma-delimited list of hosts (beginning with http:// or https://) or    *
 * "*" to allow all domains CORS access.                                    *
 *                                                                          *
 ***************************************************************************/
origin: '*',

/***************************************************************************
 *                                                                          *
 * Allow cookies to be shared for CORS requests?                            *
 *                                                                          *
 ***************************************************************************/
credentials: true,

/***************************************************************************
 *                                                                          *
 * Which methods should be allowed for CORS requests? This is only used in  *
 * response to preflight requests (see article linked above for more info)  *
 *                                                                          *
 ***************************************************************************/
methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',

/***************************************************************************
 *                                                                          *
 * Which headers should be allowed for CORS requests? This is only used in  *
 * response to preflight requests.                                          *
 *                                                                          *
 ***************************************************************************/
headers: 'content-type, access-control-allow-origin, authorization'
  angular
.module('frontend', [
  'ionic', 'ionic.service.core',
  'frontend.core',
  'ionic.service.analytics',
  //'cacheapp',
  //'cachemodule',
  'ionic-cache-src',
  'formlyIonic',
  'pascalprecht.translate',
  'angularMoment',
  'ionic.components',
  'ngFacebook',
  'translate.app',
  'translate.form',
  'angular-cache',
  'ngCordova',
  'gettext',
  'module.user',
  'module.gallery'
])
.constant('AccessLevels',{
      anon: 0,
      user: 1,
      admin: 2
})
.constant('BackendConfig',{
  url: "http://api-test-dev.com:1337",
  //url: "http://ip_of_my_phone:1337"
  //url: "10.0.2.2"
  //url: "10.0.2.2:1337"
  //url:"http://ip_of_my_phone"
  //url:"http://ip_of_my_wifi"
  //url:"http://ip_of_my_wifi:1337"
})