Ionic android app can’t communicate with Express backend

I am trying to build my perfectly working ionic web app to android. The app launches, but can’t communicate with my Express backend. I get this error :

Msg: Mixed Content: The page at 'https://localhost/login' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://{{ip}}:3000/getGroupsNameOfUser'. This request has been blocked; the content must be served over HTTPS.
(with getGroupsNameOfUser being a app.post() of my express server, and {{ip}} the local ip of the computer runing express that I prefer not to share just in case).

I understand that my android app is in https and doesn’t like to communicate with a server in http.

To solve this, I have tried enabling mixed content by adding this line in AndroidManifest.xml:
android:usesCleartextTraffic="true" but it just doesn’t work (I still get the same error).

I have then tried by adding a network_security_config.xml in res/xml/, filled with :

<network-security-config>
    <domain-config cleartextTrafficPermitted="true">

        <domain includeSubdomains="true">http://192.168.1.15:3000</domain>
        <domain includeSubdomains="true">http://127.0.0.1:3000</domain>
    </domain-config>
</network-security-config>

And adding this line in AndroidManifest.xml : android:networkSecurityConfig="@xml/network_security_config" but it doesn’t work either…

I have then tried the recommended solution: putting my express server on ssl. I created self-signed keys with this command : sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ./selfsigned.key -out selfsigned.crt. I had an error when using them so I used a command I found online : sudo chmod 755 selfsigned.key.

I then wrote my main js script:

const options = {
  key: fs.readFileSync('keys/selfsigned.key'),
  cert: fs.readFileSync('keys/selfsigned.crt')
};

const app = express ();

app.use(bodyParser.json());

app.use(cors({origin: true, credentials: true}));

app.use(cookieParser());


... (multiple app.post(...))


https.createServer(options, app).listen(3000, () => {
  console.log('HTTPS server listening on port 3000');
});

Finally I changed the adress used in my ionic app with HttpClient to “https://{{ip}}:3000/”.

But it still doesn’t work. I get this error :

[ERROR:ssl_client_socket_impl.cc(879)] handshake failed; returned -1, SSL error code 1, net_error -202

2024-05-25 12:08:30.335 22173-22173 Capacitor/Console       io.ionic.starter                     E  File: https://localhost/main.262cd90795cda89d.js - Line 1 - Msg: ERROR [object Object]

2024-05-25 12:08:31.178  1588-2373  VerityUtils             system_server                        E  Failed to measure fs-verity, errno 1: /data/app/~~DnQFZdmZ2tBOfRYWJyZ4Rw==/io.ionic.starter-bZlHBiUj6Wi4udiAfuiCCA==/base.apk

2024-05-25 12:08:31.306  1588-2373  VerityUtils             system_server                        E  Failed to measure fs-verity, errno 1: /data/app/~~DnQFZdmZ2tBOfRYWJyZ4Rw==/io.ionic.starter-bZlHBiUj6Wi4udiAfuiCCA==/base.apk

I don’t understand if the issue is from my backend or my app. I have tried “converting” my key to der with this command : openssl x509 -outform der -in selfsigned.crt -out server.der and adding the file to my phone’s trusted certificates. But it still doesn’t do anything.

Since I can do post requests with postman on https://localhost:3000, I suppose that my express works correctly, at least locally. I have tried with postman on another computer, and it works to if I disable ssl verification. If I try with the webapp (launch with ionic serve --ssl), I get a cors error that I can’t manage to solve, but I won’t care as long as my android app works, which it still does not T.T.

I am completely desperate, I don’t know what else to try. Can anyone help me ?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật