[英]FAILED TO CONNECT TO /127.0.0.1:443 - ANDROID STUDIO
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 ".当我尝试在 android 工作室中运行我的应用程序项目时,我遇到了这种问题,它一直给我一个错误“无法连接到 /127.0.0.1:443 ”。 im using local ip for that.
我为此使用本地 ip。 but when i try using 192.168.1.10 or 10.0.2.2 it doesn't work too.
但是当我尝试使用 192.168.1.10 或 10.0.2.2 时它也不起作用。
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 }}在我的复古代码中有 2 个这样的符号}}
and this is my androidmanifest.xml code这是我的 androidmanifest.xml 代码
<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如果你们能帮我解决这个问题,非常感谢
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.如果你在 localhost 中运行,你应该使用
http://10.0.2.2:8080/
作为基础 url,你需要指定端口,否则它将不起作用。
Can you do simple test in your emulator.你能在你的模拟器中做简单的测试吗? From your emulator.
从你的模拟器。 Can you open your browser.
能不能打开浏览器。 After that, open your URL.
之后,打开您的 URL。 (10.0.2.2) If everything good.
(10.0.2.2) 如果一切顺利。 Then you need to setup network_config in your android manifest.
然后您需要在 android 清单中设置 network_config。 Please checkhttps://developer.android.com/training/articles/security-config
请查看https://developer.android.com/training/articles/security-config
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
</domain-config>
<base-config cleartextTrafficPermitted="false" />
</network-security-config>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.