美文网首页
Retrofit使用https

Retrofit使用https

作者: 白日梦__ | 来源:发表于2017-04-27 14:20 被阅读278次

参考这个链接
但是我这样做了还是无效
请求的时候
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();

相关文章

网友评论

      本文标题:Retrofit使用https

      本文链接:https://www.haomeiwen.com/subject/xkogzttx.html