CLEARTEXT communication not supported on Retrofit

后端 未结 5 1830
北荒
北荒 2020-12-05 22:34

I\'m trying to connect to https server on android using Retrofit. Here\'s my OkHttpClient

@Provides
public OkHttpClient provideContactClient(){
         


        
5条回答
  •  攒了一身酷
    2020-12-05 23:30

    According to Network security configuration

    The guidance in this section applies only to apps that target Android 8.1 (API level 27) or lower. Starting with Android 9 (API level 28), cleartext support is disabled by default.

    Create file res/xml/network_security_config.xml

    
    
        
            Your URL(ex: 127.0.0.1)
        
    
    

    AndroidManifest.xml

    
    
        
        
            ...
        
    
    

    OR you can directly set in application in manifest like this.

    
    
        
        
            ...
        
    
    

提交回复
热议问题