cleartext http traffic to not permitted

Cleartext HTTP traffic to not permitted When using httpurlconnection for HTTP request in Android P, the following exception will appear

W/system.err: cleartext HTTP traffic to * * not permitted 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


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


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:

Similar Posts: