我们首先Builder了一个OkhttpClient对象,并为其添加了一个请求日志的拦截器,紧接着初始化了Retrofit为其添加RxJavaCallAdapter,最后以HttpInterface为参数将retrofit创建为HttpInterface,这样我们就可以用httpInterface封装一个调用之前所描述的getTopMovie接口方法,在这个方法中我们会将Retrofit完成请求返回的被观察者订阅起来,...
Call<PostTranslation> getCall(@Field("i") String targetSentence);//采用@Post表示Post方法进行请求(传入部分url地址)//采用@FormUrlEncoded注解的原因:API规定采用请求格式x-www-form-urlencoded,即表单形式//需要配合@Field使用} 3.2:描述GET请求的接口 IGetRequest packageldl.cn.ldldemo.get;importretrofit2....
implementation'com.squareup.retrofit2:retrofit:2.9.0'implementation'com.google.code.gson:gson:2.8.8'implementation'com.squareup.okhttp3:okhttp:4.9.1'implementation'com.squareup.retrofit2:retrofit:2.9.0'implementation'com.squareup.retrofit2:converter-gson:2.9.0'implementation'com.squareup.retrofit2:co...
您还使用了 retrofit 2.0 在 gradle 文件中添加依赖项,如下所示…compile 'com.squareup.retrofit2:retrofit:2.3.0' 将每个 api 调用和数据显示到日志中 cat 添加到 depencey 下方 ..compile 'com.squareup.okhttp3:logging-interceptor:3.4.1' 在为api 设置一类之后,如下所示 ..class ApiClient { companion...
Android kotlin 封装Flow网络请求回调函数,一、简介它和OkHttp的定位完全不同。OkHttp侧重的是底层通信的实现,而Retrofit侧重的是上层接口的封装。事实上,Retrofit就是Square公司在OkHttp的基础上进一步开发出来的应用层网络通信库,使得我们可以用更加面向对象的思维进
最近学习了Kotlin,感受就是好处太多了 欲罢不能,这其中协程这个特点处理异步非常不错,于是花了很长时间结合Retrofit封装了网络请求,感觉非常简洁好用。 准备工作:Retrofit的初始化 常规写法 引入第三方 implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" ...
由于经验逐渐变得丰富,你开始使用Kotlin的协程,因为你对更牛逼技术的追求一直没有停止过。 interfaceAuthService{@POST("v6/login")suspendfunlogin(@Bodybody:RequestBody):BaseResponse<LoginUser>} 这个时候retrofit的写法就已经进入到了第6代,你问为什么是第6代?这个不是重点,我编的。你直接将API接口中定义的函数...
由于经验逐渐变得丰富,你开始使用Kotlin的协程,因为你对更牛逼技术的追求一直没有停止过。 interface AuthService { @POST("v6/login") suspend fun login(@Body body: RequestBody): BaseResponse<LoginUser> } 这个时候retrofit的写法就已经进入到了第6代,你问为什么是第6代?这个不是重点,我编的。你直接将API...
https://github.com/Kotlin/kotlinx.coroutines retrofit:官方依赖及源码地址,移步github: https://github.com/ReactiveX/RxJava 1.首先将最新的依赖版本加入as gradle中并sync 2.清单文件加入网络权限:<uses-permission android:name="android.permission.INTERNET" /> ...
这是通过注解自动生成的文件,使用了kotlinpoet 并且这里apiService就是通过Retrofit拿到的接口代理 3.在viewmodel拿到对应Repository类的方法 4.在对应地方通过viewmodel调用 调用接口,传入对应参数 在合适的地方观察 Retrofit的封装 上面说到在Repository类的apiService就是通过Retrofit拿到的接口代理类。 所以先进去看看apiSer...