CLEARTEXT communication not supported on Retrofit

后端 未结 5 1834
北荒
北荒 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:14

    The CLEARTEXT message is due to requesting an http URL, either directly or via a server-side redirect (e.g., starts with https, then redirects to http).

    In terms of your "trust anchor for certification path not found" message, your server appears to be using some SSL certificate that is not backed by one of the standard ones on whatever Android environment you are testing on. For example, perhaps your server is using an self-signed SSL certificate.

    Options include:

    • Using network security configuration on Android 7.0+

    • Using my backport of network security configuration on Android 4.2+

    • Setting up an SSLContext that knows about your self-signed certificate, then attaching that to OkHttp, such as is illustrated by this OkHttp recipe

提交回复
热议问题