We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OkHttpClient
在3.0版本之前,默认支持自签名的https,配置如下:
//Default OkHttpClient object in RxHttp private static OkHttpClient getDefaultOkHttpClient() { SSLParams sslParams = HttpsUtils.getSslSocketFactory(); return new OkHttpClient.Builder() .connectTimeout(10, TimeUnit.SECONDS) .readTimeout(10, TimeUnit.SECONDS) .writeTimeout(10, TimeUnit.SECONDS) .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager) .hostnameVerifier((hostname, session) -> true) .build(); }
3.0版本则取消对自签名https的默认支持,更改后的如下:
//Default OkHttpClient object in RxHttp private static OkHttpClient getDefaultOkHttpClient() { return new OkHttpClient.Builder().build(); //okhttp内部读、写、连接超时均为10s }
所以,如果你之前没有自定义OkHttpClient对象,且需要支持没有证书的https网站,则需要自定义OkHttpClient对象,如下:
//建议在Application中调用 public static void init() { SSLParams sslParams = HttpsUtils.getSslSocketFactory(); OkHttpClient client = new OkHttpClient.Builder() .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager) //添加信任证书 .hostnameVerifier((hostname, session) -> true) //忽略host验证 .build(); RxHttpPlugins.init(client) //自定义OkHttpClient对象 .setDebug(BuildConfig.DEBUG, false, 2) //调试模式/分段打印/json数据格式化输出 .setOnParamAssembly(p -> { //设置公共参数,非必须 }); }
目前由之前的rxhttp.wrapper.cahce改为rxhttp.wrapper.cache,如有用到,重新导入即可
rxhttp.wrapper.cahce
rxhttp.wrapper.cache
asXxx/toXxx/toFlowXxx
RxJava环境的asXxx方法改为了toObserableXxx
asXxx
toObserableXxx
Await环境的toXxx系列方法改为toAwaitXxx方法
toXxx
toAwaitXxx
Flow环境仅更改了下载系列方法,由toFlow改为toDownloadFlow
toFlow
toDownloadFlow
以上详细更改,请查看3.0 toObserableXxx/toAwait/toFlowxxx方法介绍
public static void init() { RxHttpPlugins.init(client) .setDebug(BuildConfig.DEBUG, false, 2) .setOnParamAssembly(p -> { // return p; 3.0版本前,需要写return语句,3.0版本则不需要 }); }
//3.0之前 RxHttp.postForm("/service/...") .addFile("file", File("sd卡路径")) .upload(AndroidSchedulers.mainThread()) { //上传进度回调,主线程 } .asClass<User>() .subscribe({ //成功回调 }, { //异常回调 }) //3.0 RxHttp.postForm("/service/...") .addFile("file", File("sd卡路径")) .toObservable<User>() .onMainProgress { //当然也可以调用onProgress指定回调线程 //上传进度回调,主线程 } .subscribe({ //成功回调 }, { //异常回调 })
对于Await/Flow下载,仅仅是更改了方法名,由3.0前的toDownload/toFlow改为了toDownloadAwait/toDownloadFlow;
Await/Flow
toDownload/toFlow
toDownloadAwait/toDownloadFlow
而RxJava,不仅更改了方法名,还调整了下载进度监听方式,跟监听上传进度一样,如下:
RxJava
//3.0之前 RxHttp.get("/service/.../xxx.apk") .asDownload("sd卡路径", AndroidSchedulers.mainThread()) { //断点下载调用asAppendDownload方法 //下载进度回调,主线程 } .subscribe({ //成功回调,这里返回sd卡存储路径 }, { //异常回调 }) //3.0 RxHttp.get("/service/.../xxx.apk") .toDownloadObservable("sd卡路径", Boolean) //断点下载第二个参数传true .onMainProgress { //当然也可以调用onProgress指定回调线程 //下载进度回调,主线程 } .subscribe({ //成功回调,这里返回sd卡存储路径 }, { //异常回调 })
//3.0之前 RxHttp.get("/service/...") .setSync() .asClass<User>() .subscribe() //3.0 RxHttp.get("/service/...") .toObservable<User>() .syncRequest() //syncRequest替代setSync,并且需要在toObservableXxx方法后调用 .subscribe()
删除RxJava下的asBitmap/asHeaders()/asOkResponse方法
asBitmap/asHeaders()/asOkResponse
删除Await下的toBitmap/toHeaders()/toOkResponse方法
toBitmap/toHeaders()/toOkResponse
删除Flow下的toFlowBitmap/toFlowHeaders()/toFlowOkResponse方法
toFlowBitmap/toFlowHeaders()/toFlowOkResponse
//3.0获取Bitmap RxHttp.get("/server/...") .toObservable<Bitmap>() //RxJava //.toAwait<Bitmap>() //Await //.toFlow<Bitmap>() //Flow //3.0获取Headers/OkHttp3.Response RxHttp.get("/server/...") .toObservable<OkResponse<User>>() //Await/Flow 调用 toAwait/toFlow .subscribe({ val headers = it.headers() //Headers val response = it.raw() //OkHttp3.Response val user = it.body() }, { //异常回调 })
The text was updated successfully, but these errors were encountered:
#409
Sorry, something went wrong.
No branches or pull requests
1、默认
OkHttpClient
更改在3.0版本之前,默认支持自签名的https,配置如下:
3.0版本则取消对自签名https的默认支持,更改后的如下:
所以,如果你之前没有自定义
OkHttpClient
对象,且需要支持没有证书的https网站,则需要自定义OkHttpClient
对象,如下:2、缓存功能相关类目录更改
目前由之前的
rxhttp.wrapper.cahce
改为rxhttp.wrapper.cache
,如有用到,重新导入即可3、
asXxx/toXxx/toFlowXxx
方法更改RxJava环境的
asXxx
方法改为了toObserableXxx
Await环境的
toXxx
系列方法改为toAwaitXxx
方法Flow环境仅更改了下载系列方法,由
toFlow
改为toDownloadFlow
以上详细更改,请查看3.0 toObserableXxx/toAwait/toFlowxxx方法介绍
4、setOnParamAssembly公共参数回调更改
5、RxJava上传进度监听方式更改
6、RxJava/Await/Flow下载方法更改
对于
Await/Flow
下载,仅仅是更改了方法名,由3.0前的toDownload/toFlow
改为了toDownloadAwait/toDownloadFlow
;而
RxJava
,不仅更改了方法名,还调整了下载进度监听方式,跟监听上传进度一样,如下:7、RxJava同步请求方法setSync更改
8、获取Bitmap/Headers/OkHttp3.Response对象方式更改
删除RxJava下的
asBitmap/asHeaders()/asOkResponse
方法删除Await下的
toBitmap/toHeaders()/toOkResponse
方法删除Flow下的
toFlowBitmap/toFlowHeaders()/toFlowOkResponse
方法The text was updated successfully, but these errors were encountered: