【问题标题】:FAILED TO CONNECT TO /127.0.0.1:443 - ANDROID STUDIO无法连接到 /127.0.0.1:443 - ANDROID STUDIO
【发布时间】:2022-01-05 08:46:37
【问题描述】:

当我尝试在 android studio 中运行我的应用项目时遇到这种问题,它一直给我一个错误“无法连接到 /127.0.0.1:443”。我为此使用本地IP。但是当我尝试使用 192.168.1.10 或 10.0.2.2 时它也不起作用。

这是我的复古代码

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;
}

在我的复古代码中有 2 个这样的符号}}

这是我的 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>

如果你们能帮我解决这个问题,非常感谢

【问题讨论】:

  • try to run my app project in android studio ?你在做什么?我宁愿认为您会尝试在 Android 手机上运行您的 Android 应用程序。很不清楚。
  • 我必须在 android studio 模拟器上运行该应用程序,因为这个应用程序用于我的期末考试,我必须稍后展示它
  • 请删除android-studio 标签。并在您的帖子中说明您使用的是模拟器。

标签: java android android-studio localhost ip


【解决方案1】:

如果你在localhost中运行你应该使用http://10.0.2.2:8080/作为base url,你需要指定端口,否则它将不起作用。

【讨论】:

    【解决方案2】:

    你能在你的模拟器中做简单的测试吗? 从你的模拟器。 能不能打开浏览器。之后,打开您的网址。 (10.0.2.2) 如果一切都好。 然后你需要在你的 android manifest 中设置 network_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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-02
      • 1970-01-01
      • 1970-01-01
      • 2020-11-19
      • 2016-11-20
      • 1970-01-01
      • 1970-01-01
      • 2019-10-20
      相关资源
      最近更新 更多