简体   繁体   English

无法通过离子安卓应用程序通过https连接到后端

[英]Not able to connect to backend over https from ionic android app

Unable to connect to backend over "https" on android app created through ionic CLI. 无法通过ionic CLI在android应用上通过“ https”连接到后端。

It works perfectly fine on browser, on debug mode on android phone. 它在浏览器上,在Android手机上的调试模式下都可以正常工作。 Just doesn't work in release mode. 只是在发布模式下不起作用。 It even works over 'http' but not on 'https'. 它甚至可以在“ http”上运行,但不能在“ https”上运行。

And my SSL certificate is not self-signed. 而且我的SSL证书不是自签名的。 It is properly bought certificate and all SSL checkers say it is fine. 这是正确购买的证书,所有SSL检查人员都说很好。

Tried all the solutions I could find on internet. 尝试了所有可以在互联网上找到的解决方案。

  1. Installed whitelist-plugin. 已安装白名单插件。
  2. Re-installed whitelist-plugin. 重新安装了白名单插件。
  3. Added Content-security-policy with "*" for default-src. 为default-src添加了带有“ *”的Content-security-policy。

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src * 'unsafe-inline'; media-src *; script-src *;">

  1. Added <allow-intent href="*" /> <allow-navigation href="*" /> 添加了<allow-intent href="*" /> <allow-navigation href="*" />

Looks like app itself blocking the request from going out. 看起来应用本身阻止了请求发出。 Nothing seems working. 似乎没有任何作用。 Please help. 请帮忙。

The very simple solutions is, allow two ports in your API like 非常简单的解决方案是,在您的API中允许两个端口

3001 for SSL / HTTPS and 3002 for HTTP.. This way your app works and your site runs perfectly in HTTPS 3001(用于SSL / HTTPS)和3002(用于HTTP)。这样,您的应用可以正常工作,并且您的网站可以在HTTPS中完美运行

My code is as follows which worked perfectly: 我的代码如下,效果很好:

 var express = require('express'); var DataController = require('./user/DataController'); var UserController = require('./user/UserController'); var db = require('./database/database-db'); var cors = require('cors'); var app = express(); app.use(cors()); app.use(function(req, res, next) { res.setHeader("Access-Control-Allow-Origin", "*"); res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); res.setHeader('Access-Control-Allow-Methods', 'POST'); res.setHeader('Access-Control-Allow-Credentials', true); next(); }); app.use('/user', UserController); app.use('/data', DataController); app.get('/', function(req, res){ res.send("Welcome to the secure mobile and web development world"); }); // This settings are for HTTPS, SSL web applications. // var https = require("https"); // var fs = require("fs"); // var options = { // key: fs.readFileSync("/home/path/ssl/keys/key.key"), // cert: fs.readFileSync("/home/path/ssl/certs/crt.crt") // }; // https.createServer(options,app).listen(3001); // console.log('Welcome to the security world') // This settings are only for HTTP sites // var http = require("http"); // var fs = require("fs"); // http.createServer(app).listen(3001); // console.log('Welcome to the security') //This settings are for both HTTPS,HTTP SSL web applications. var https = require("https"); var http = require("http"); var fs = require("fs"); var options = { key: fs.readFileSync("/home/path/ssl/keys/key.key"), cert: fs.readFileSync("/home/path/ssl/keys/crt.crt") }; https.createServer(options,app).listen(3001); console.log('Welcome to the security world') http.createServer(app).listen(3002); console.log('Welcome to the proxy world') 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从Android模拟器连接安全站点(“ https:”) - Not able to connect secure sites (“https:”) from android emulator 如何从代理后面的Android应用通过HTTPS访问服务? - How to access services over HTTPS from Android app behind proxy? 想要设置一个将连接到后端数据库的Android应用 - want to setup an Android app that will connect to a backend database Android应用程序连接到后端数据库/网站 - Android app to connect to backend database / website 将android客户端与后端应用程序引擎模块连接 - Connect android client with backend app engine module 后端设计以连接到 android 应用程序和 web ui - backend design to connect to android app and web ui 如何从back4app.com连接到Qt Android应用程序解析服务器后端 - How to connect to parse server backend from back4app.com for Qt android app 无法连接手机上运行的Android应用程序与localhost - Not able to connect android app running on phone with localhost 带有 .net 核心后端的 Ionic 使用电容器到 android 应用程序 - Ionic with .net core backend to android app using capacitor 无法从Android设备上的本机应用程序连接到meteor后端 - Can't connect to meteor backend from react native app at android device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM