Tag Archives: Cleartext HTTP traffic to 192.168.1.106 not permitted

cleartext http traffic to 192.168.1.106 not permitted

Cleartext HTTP traffic to 192.168.1.106 not permitted https://blog.csdn.net/gengkui9897/article/details/82863966 When using httpurlconnection for HTTP request in Android P, the following exception will appear

W/system.err: java.io.ioexception: cleartext HTTP traffic to * * not permitted

Java.net.unknownserviceexception: cleartext communication * * not permitted by network security policy on Android P system devices, if the application uses HTTP network request of unencrypted plaintext traffic, it will cause the application unable to make network request, and HTTPS will not be affected. Similarly, if the application nested WebView, WebView can only use HTTPS requests

There are three ways to solve this problem

(1) App uses HTTPS request instead

(2) Targetsdkversion is below 27

(3) Change network security configuration

The first two methods are easy to understand and implement. The third method is to change the network security configuration

1. Create an XML folder under res folder, and then create a network_ security_ The content of the file is as follows:

<?xml version=”1.0″ encoding=”utf-8″?>

< network-security-config> & lt; base-config cleartextTrafficPermitted=”true” /> & lt;/ network-security-config> 2. Next, add the following attributes to the application tag in the androidmanifest.xml file:

< application … android:networkSecurityConfig= “@xml/network_ security_ config” … /> After that, the app will be able to access the network

——Update——

Method 4: in the & lt; application> Insert directly into the tag (thank you junbs for sharing)

android:usesCleartextTraffic="true"

Copyright notice: This is the original article of CSDN blogger “yuzijun”, which is in accordance with CC 4.0 by-sa copyright agreement. Please attach the link of original source and this notice. Link to the original text: https://blog.csdn.net/gengkui9897/article/details/82863966