Retrofit与okhttp共同出自于Square公司,retrofit就是对okhttp做了一层封装。把网络请求都交给给了Okhttp,我们只需要通过简单的配置就能使用retrofit来进行网络请求了,其主要作者是Android大神JakeWharton。
导包:
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'//Retrofit2所需要的包
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'//ConverterFactory的Gson依赖包
compile 'com.squareup.retrofit2:converter-scalars:2.0.0-beta4'//ConverterFactory的String依赖包
*这里需要值得注意的是导入的retrofit2包的版本必须要一致,否则就会报错。
首先定义我们请求的Api,我们假设是这样的
http://106.3.227.33/pulamsi/mobileLogin/submit.html
与Okhttp不同的是,Retrofit需要定义一个接口,用来返回我们的Call对象,这里示范的是Post请求:
public interface RequestServes { @POST("mobileLogin/submit.html") Call<String> getString(@Query("loginname") String loginname, @Query("nloginpwd") String nloginpwd); }
分享题目:AndroidRetrofit的简单介绍和使用-创新互联
标题来源:https://www.cdcxhl.com/article46/dgcjhg.html
成都网站建设公司_创新互联,为您提供网站设计、云服务器、小程序开发、移动网站建设、Google、微信小程序
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联