Retrofit使用https

参考这个链接
但是我这样做了还是无效
请求的时候
stream was reset: PROTOCOL_ERROR错误
最后google了一下,在OkHttpClient中加了一行代码才有效

OkHttpClient httpClient = new OkHttpClient.Builder()
                .addInterceptor(new Interceptor() {
                    @Override
                    public okhttp3.Response intercept(Chain chain) throws IOException {
                        Request request = chain.request()
                                .newBuilder()
                                .addHeader("SdkVersion", "1")
                                .addHeader("Authorization", BaseApplication.getInstance().getToken())
                                .addHeader("Model", BaseApplication.getInstance().getModel())
                                .build();
                        return chain.proceed(request);
                    }
                })
                .sslSocketFactory(getSSLSocketFactory(BaseApplication.getInstance()))
                //加上这行代码https才有效
                .protocols(Collections.singletonList(Protocol.HTTP_1_1))
                .build();

推荐阅读更多精彩内容