Bug 网络请求报错 CLEARTEXT communication to 192.168.3.243 not permitted by network security policy

╰+攻爆jí腚メ 2023-09-27 12:37 143阅读 0赞

" class="reference-link">dc80deb8bebd4262b4c37e6ae48ef2e6.png

Bug报错:

CLEARTEXT communication to 192.168.3.243 not permitted by network security policy

解决:

方法一:当使用HTTP时出现报错可以尝试将HTTP 更换为HTTPS

方法二:
如果方法一不能用可以尝试在mainifest中加入如下代码

  1. <uses-permission android:name="android.permission.INTERNET" />
  2. <application
  3. android:usesCleartextTraffic="true"
  4. <!-- Android 9.0是默认禁止所有http请求的,需要在代码中设置如以下代码才可以正常进行网络请求-->
  5. <uses-library
  6. android:name="org.apache.http.legacy"
  7. android:required="false" />

。。。

4fb2e708ad204051861933fdcc76d03a.png

  1. <!-- 网络权限 -->
  2. <uses-permission android:name="android.permission.INTERNET" />
  3. <!-- 允许使用流量 -->
  4. <!-- android:usesCleartextTraffic="true" -->
  5. <application
  6. android:allowBackup="true"
  7. android:dataExtractionRules="@xml/data_extraction_rules"
  8. android:fullBackupContent="@xml/backup_rules"
  9. android:icon="@mipmap/ic_launcher"
  10. android:label="@string/app_name"
  11. android:roundIcon="@mipmap/ic_launcher_round"
  12. android:supportsRtl="true"
  13. android:theme="@style/Theme.KsxyTake"
  14. android:usesCleartextTraffic="true"
  15. tools:targetApi="31">
  16. <!-- Android 9.0是默认禁止所有http请求的,需要在代码中设置如以下代码才可以正常进行网络请求-->
  17. <uses-library
  18. android:name="org.apache.http.legacy"
  19. android:required="false" />
  20. <activity
  21. android:name=".LogonActivity"
  22. android:exported="true">
  23. <intent-filter>
  24. <action android:name="android.intent.action.MAIN" />
  25. <category android:name="android.intent.category.LAUNCHER" />
  26. </intent-filter>
  27. <meta-data
  28. android:name="android.app.lib_name"
  29. android:value="" />
  30. </activity>

。。。

发表评论

表情:
评论列表 (有 0 条评论,143人围观)

还没有评论,来说两句吧...

相关阅读