Java 我尝试连接192.168.1.20/localhost/10.0.2.2,但不工作
我试图连接到Ubuntu中的改造。它执行失败方法。我也尝试了端口8080和3000。我不知道哪里出了问题。它完全可以在服务器url上工作 emulator显示错误为无法连接到10.0.2.2:3000 manifest.xmlJava 我尝试连接192.168.1.20/localhost/10.0.2.2,但不工作,java,android,android-studio,networking,retrofit,Java,Android,Android Studio,Networking,Retrofit,我试图连接到Ubuntu中的改造。它执行失败方法。我也尝试了端口8080和3000。我不知道哪里出了问题。它完全可以在服务器url上工作 emulator显示错误为无法连接到10.0.2.2:3000 manifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ex
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.brg_dsk005.pikaainstruction">
<uses-permission android:name="android.permission.INTERNET"/>
<application
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/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
接口:
@POST("take_tests")
Call<Test_Responce> testRes (@Body JsonObject paramObject);
可能是,它无法访问本地主机网络,请在android清单中添加以下权限,然后重试
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
我希望这段代码对你有用, 试试这个
10.0.2.2 is your local ip? print the url in log and share, can you post your error log
请分享改装代码alsonow i分享改装代码alsois您的模拟器是Google Android虚拟设备还是Genymotion Android虚拟设备?您正在使用哪个本地服务器作为API,以及为什么要尝试8080和3000,这似乎只是点击并尝试。如果连接到网络,您应该知道本地服务器运行的端口号以及ip。所以格式可以是http://ipaddress:port/testengine/public/api/10.0.2.2 您的本地ip地址是多少?在日志和共享中打印url,您可以发布错误日志吗
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
10.0.2.2 is your local ip? print the url in log and share, can you post your error log