當我嘗試在 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>
如果你們能幫我解決這個問題,非常感謝
uj5u.com熱心網友回復:
如果您在 localhost 中運行,則應將其http://10.0.2.2:8080/用作基本 url,您需要指定埠,否則將無法正常作業。
uj5u.com熱心網友回復:
你能在你的模擬器中做簡單的測驗嗎?從你的模擬器。能不能打開瀏覽器。之后,打開您的網址。(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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/406321.html
標籤:
