Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android emulator – Flutter – Insecure socket connections are disallowed by platform: 10.0.2.2

Posted on November 14, 2022

Solution 1 :

I have a similar issue with Flutter running on ios Simulator and Android emulator:

SocketException: Insecure socket connections are disallowed by platform:

Inside the Flutter project go to :

To enable in Ios:

ios folder -> runner folder -> info.plist

Then add the following lines to enable HTTP requests:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>

To enable in Android:

Android folder -> app -> src -> main -> AndroidManifest.xml

Add this permission:

<uses-permission android_name="android.permission.INTERNET"/>

then add the following line inside application tag:

android:usesCleartextTraffic="true"

Solution 2 :

First add-in AndroidManifest file

add this line in the end before closing tag

<uses-permission android_name="android.permission.INTERNET" />

add this line in the beginning
find this tag and add it first in it

<application
    android_usesCleartextTraffic="true"

Solution 3 :

It seems you newly upgraded to Android 10, Well you probably didn’t know that HTTPS is the default connection protocol starting with Android 9 and that all connection not using Https will fail.
Read more https://developer.android.com/training/articles/security-config.html

See this answer here
https://stackoverflow.com/a/50834600/6467637

Solution 4 :

I was making a call to-
Response response = await get(‘http://worldtimeapi.org/api/timezone/Asia/Kolkata’);

Instead of http I simply replaced it to https and it was fixed.

The new request was-
Response response = await get(‘https://worldtimeapi.org/api/timezone/Asia/Kolkata’);

This fixed the issue for me.

Problem :

Since today whenever I try to login my application I get the following error thrown by the Dio package: SocketException: Insecure socket connections are disallowed by platform: 10.0.2.2

I use the following settings to connect:

static BaseOptions options = new BaseOptions(
    baseUrl: "http://10.0.2.2:3000", // on android emulator
    connectTimeout: 5000,
    receiveTimeout: 3000)

And consequently something along the lines of (where I have authentication set-up and functioning properly at /user/login):

var apiLogin = api.dio;
try {
Response response = await apiLogin.post("/user/login",
          options: Options(contentType: "application/json"),
          data: {"email": email, "password": password});
} on DioError catch (e) {
throw Exception([e]);
} 

I have a Node server running on port 3000 which is connected to (containerized) mongodb. When trying the authentication, it immediately has the DioError and I haven’t been able to find the cause anywhere online.

READ  [ANSWERED] android studio - woocommerce_rest_cannot_view with oauth 1.0
Powered by Inline Related Posts

Does anyone know what this error is related to?

EDIT [ANSWER]

Thanks to @lyrics for pointing me in the right direction:
From API level 27 and higher, usesCleartextTraffic defaults to false, consequently blocking outgoing http requests, requiring HTTPS.

The solution was to add the following to AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android_name="android.permission.INTERNET" />
    <application
        ...
        android_usesCleartextTraffic="true"
        ...>
        ...
    </application>
</manifest>

as stated in stackoverflow answer

source: https://developer.android.com/guide/topics/manifest/application-element#usesCleartextTraffic

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress