i have this kind of problem when i try to run my app project in android studio it keeps give me an error "failed to connect to /127.0.0.1:443". im using local ip for that. but when i try using 192.168.1.10 or 10.0.2.2 it doesn’t work too.
this is my retro code
public class RetroServer {
private static final String baseURL = "https://127.0.0.1/laundry/";
private static Retrofit retro;
public static Retrofit konekRetrofit(){
if(retro == null){
retro = new Retrofit.Builder()
.baseUrl(baseURL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retro;
}
in my retro code there’s 2 of this symbols }}
and this is my androidmanifest.xml code
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Laundry">
<activity
android:name=".Activity.MainActivity"
android:exported="true"
tools:ignore="MissingClass">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
if you guys can help me with this problem, thank you so much
2
Answers
If you are running in localhost you should use
http://10.0.2.2:8080/
as a base url, you need to specify the port, otherwise it won’t work.Can you do simple test in your emulator.
From your emulator.
Can you open your browser. After that, open your URL. (10.0.2.2)
If everything good.
Then you need to setup network_config in your android manifest.
Please check https://developer.android.com/training/articles/security-config