Volley 库连接不上 10.0.2.2
Volley library does not connect to 10.0.2.2
我已将 volley 库添加到我的 android 项目中。我正在使用 android 模拟器。我只想从本地主机获取数据。这就是为什么我将 url 设置为 http://10.0.2.2/test.php .
但是问题是 volley 没有连接到这个地址。但是在我的 android 模拟器中,我尝试使用 link 和 google chrome。它工作正常。但是,如果我将 url 更改为 google.com 或其他网站,排球图书馆工作正常。只有 http://10.0.2.2/test.php 这个 url 在 volley 中不工作,但在 Android 模拟器中的其他浏览器不工作。
谁能告诉我 volley 库不支持这个本地主机 ip 10.0.2.2?
错误:
com.android.volley.NoConnectionError: java.io.IOException: Cleartext
HTTP traffic to 10.0.2.2 not permitted
解法:
在您的清单中添加这一行:
android:usesCleartextTraffic="true"
因为我在 Laravel 上的 php 页面遇到了同样的问题。
它应该是这样的:
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
</manifest>
希望它能奏效。
我已将 volley 库添加到我的 android 项目中。我正在使用 android 模拟器。我只想从本地主机获取数据。这就是为什么我将 url 设置为 http://10.0.2.2/test.php .
但是问题是 volley 没有连接到这个地址。但是在我的 android 模拟器中,我尝试使用 link 和 google chrome。它工作正常。但是,如果我将 url 更改为 google.com 或其他网站,排球图书馆工作正常。只有 http://10.0.2.2/test.php 这个 url 在 volley 中不工作,但在 Android 模拟器中的其他浏览器不工作。
谁能告诉我 volley 库不支持这个本地主机 ip 10.0.2.2?
错误:
com.android.volley.NoConnectionError: java.io.IOException: Cleartext HTTP traffic to 10.0.2.2 not permitted
解法:
在您的清单中添加这一行:
android:usesCleartextTraffic="true"
因为我在 Laravel 上的 php 页面遇到了同样的问题。
它应该是这样的:
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
</manifest>
希望它能奏效。