AndroidRetrofit的简单介绍和使用-创新互联
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") CallgetString(@Query("loginname") String loginname, @Query("nloginpwd") String nloginpwd); }
网页题目:AndroidRetrofit的简单介绍和使用-创新互联
链接URL:http://jxruijie.cn/article/dgcjhg.html