1、包名改变
包名改了由之前的 com.squareup.http. 改为 okhttp3.我们需要将导包名直接换掉,另外记得修改progurad-rules.pro 文件中将对应包名
2、OkHttpClient参数配置
之前参数可以直接mOkHttpClient.setCache(cache)设置,现在OkHttpClient使用创建者模式,需要在OkHttpClient.Builder上设置可配置的参数如下:
Dispatcher dispatcher; // 分发
Proxy proxy; // 代理
List<Protocol> protocols;
List<ConnectionSpec> connectionSpecs;
final List<Interceptor> interceptors = new ArrayList<>(); // 拦截器 final List<Interceptor> networkInterceptors = new ArrayList<>(); // 网络拦截器 ProxySelector proxySelector;
CookieJar cookieJar;
Cache cache; // 缓存
InternalCache internalCache;
SocketFactory socketFactory;
SSLSocketFactory sslSocketFactory;
HostnameVerifier hostnameVerifier;
CertificatePinner certificatePinner;
Authenticator proxyAuthenticator; // 代理证书
Authenticator authenticator; // 证书
ConnectionPool connectionPool;
Dns dns; // DNS
boolean followSslRedirects;
boolean followRedirects;
boolean retryOnConnectionFailure;
int connectTimeout;
int readTimeout;
int writeTimeout;
例如:
okhttp3.0之前:
okhttp3.0之后: