【发布时间】:2020-07-12 17:51:45
【问题描述】:
我正在学习 Kotlin 的 Coroutines,我是 Retrofit 的初学者。
代码 A 来自artical。
似乎Retrofit 从本地服务器http://localhost/ 获取数据,我没有运行本地Web 服务器。
Retrofit 从哪里获取数据?
代码 A
private val service: MainNetwork by lazy {
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(SkipNetworkInterceptor())
.build()
val retrofit = Retrofit.Builder()
.baseUrl("http://localhost/")
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.build()
retrofit.create(MainNetwork::class.java)
}
fun getNetworkService() = service
/**
* Main network interface which will fetch a new welcome title for us
*/
interface MainNetwork {
@GET("next_title.json")
suspend fun fetchNextTitle(): String
}
【问题讨论】: