# AndHttp **Repository Path**: wangshiju/AndHttp ## Basic Information - **Project Name**: AndHttp - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-06-18 - **Last Updated**: 2021-10-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ```kotlin private val viewModel: MainViewModel by lazy { ViewModelProvider(this).get(MainViewModel::class.java) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // 发起请求 btnRequest1.setOnClickListener { viewModel.getChapters1() } // 请求状态 viewModel.loadState.observe(this) { when (loadState) { is LoadState.Start -> { LogUtil.LOGE("开始") } is LoadState.Error -> { LogUtil.LOGE("异常:{loadState.msg}") } is LoadState.Finish -> { LogUtil.LOGE("完成") } } // 结果 viewModel.chapters.observe(this) { it.forEach { item -> LogUtil.LOGE(item.toString()) } } } ``` ```kotlin class MainViewModel : BaseViewModel() { val chapters = MutableLiveData>() fun getChapters1() { val url = "https://wanandroid.com/wxarticle/chapters/json" launch({ loadState.postValue(it) }) { val result = HttpUtils.get>(url) chapters.postValue(result) } } } ``` ``` fun getChapters2() { val url = "https://wanandroid.com/wxarticle/chapters/json" launch({ loadState.postValue(it) }) { HttpUtils.execGet>(url) { chapters.postValue(it) } } } ```