Retrofit是一個當(dāng)前很流行的網(wǎng)絡(luò)請求庫, 官網(wǎng)的介紹是: "Type-safe HTTP client for Android and Java". 本文介紹Retrofit的使用.
先介紹單獨使用Retrofit進行網(wǎng)絡(luò)請求, 后面主要介紹和RxJava結(jié)合的請求, 有實例代碼.
Retrofit單獨使用
Setup
首先在manifest中加上網(wǎng)絡(luò)權(quán)限:
<uses-permission android:name="android.permission.INTERNET" />
然后在app/build.gradle中加上依賴:
compile 'com.squareup.retrofit2:retrofit:2.1.0' compile 'com.google.code.gson:gson:2.8.0' compile 'com.squareup.retrofit2:converter-gson:2.1.0'
準備API和model類
本例子中使用Github API做請求.
以Github的Root Endpoint為例:
https://api.github.com.
首先, 我們在命令行發(fā)送:
延伸閱讀
- ssh框架 2016-09-30
- 阿里移動安全 [無線安全]玩轉(zhuǎn)無線電——不安全的藍牙鎖 2017-07-26
- 消息隊列NetMQ 原理分析4-Socket、Session、Option和Pipe 2024-03-26
- Selective Search for Object Recognition 論文筆記【圖片目標分割】 2017-07-26
- 詞向量-LRWE模型-更好地識別反義詞同義詞 2017-07-26
- 從棧不平衡問題 理解 calling convention 2017-07-26
- php imagemagick 處理 圖片剪切、壓縮、合并、插入文本、背景色透明 2017-07-26
- Swift實現(xiàn)JSON轉(zhuǎn)Model - HandyJSON使用講解 2017-07-26
- 阿里移動安全 Android端惡意鎖屏勒索應(yīng)用分析 2017-07-26
- 集合結(jié)合數(shù)據(jù)結(jié)構(gòu)來看看(二) 2017-07-26
