Retrofit與okhttp共同出自于Square公司,retrofit就是對(duì)okhttp做了一層封裝。把網(wǎng)絡(luò)請(qǐng)求都交給給了Okhttp,我們只需要通過簡(jiǎn)單的配置就能使用retrofit來進(jìn)行網(wǎng)絡(luò)請(qǐng)求了,其主要作者是Android大神JakeWharton。
導(dǎo)包:
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依賴包
*這里需要值得注意的是導(dǎo)入的retrofit2包的版本必須要一致,否則就會(huì)報(bào)錯(cuò)。
首先定義我們請(qǐng)求的Api,我們假設(shè)是這樣的
http://106.3.227.33/pulamsi/mobileLogin/submit.html
與Okhttp不同的是,Retrofit需要定義一個(gè)接口,用來返回我們的Call對(duì)象,這里示范的是Post請(qǐng)求:
public interface RequestServes { @POST("mobileLogin/submit.html") Call<String> getString(@Query("loginname") String loginname, @Query("nloginpwd") String nloginpwd); }
分享題目:AndroidRetrofit的簡(jiǎn)單介紹和使用-創(chuàng)新互聯(lián)
標(biāo)題來源:http://www.rwnh.cn/article46/dgcjhg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)、云服務(wù)器、小程序開發(fā)、移動(dòng)網(wǎng)站建設(shè)、Google、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容