我正在创建一个android应用程序,在这个应用程序中,用户必须通过otp登录,并且要获得otp,必须向HTTP url发出请求。
除了ANDROID 11之外,它在所有安卓版本中都运行得很好,说明:
CLEARTEXT communication not enabled for client
我添加了一个网络安全配置,并在清单文件中设置了usesCleartextTraffic="true"。android 9和10的网络安全配置运行良好,但在android 11上不起作用。我使用OKHTTP发出请求。
任何帮助都将不胜感激。
发布于 2021-04-14 18:44:21
好的,我解决了这个问题,让这个问题继续存在,这样它就能帮助有同样问题的人。我通过更改OkHttpClient client =新OkHttpClient()来解决这个问题。
至
OkHttpClient client = new OkHttpClient.Builder() ConnectionSpec.MODERN_TLS)) .build();
发布于 2021-04-14 19:31:03
将其添加到AndroidManifest.xml的应用程序标记中
android:usesCleartextTraffic="true"最后一看,
<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/Theme.App"
android:usesCleartextTraffic="true"> // add this linehttps://stackoverflow.com/questions/67096497
复制相似问题