参考文章:https://blog.csdn.net/tantion/article/details/81112039
- 导入包
compileOnly 'com.squareup.okhttp3:okhttp:4.2.1'
compileOnly 'com.squareup.okhttp3:logging-interceptor:4.2.1'
compileOnly 'com.google.code.gson:gson:2.8.5'
compileOnly 'com.squareup.retrofit2:retrofit:2.6.2'
compileOnly 'com.squareup.retrofit2:converter-gson:2.6.2'
‘com.squareup.okhttp3:logging-interceptor:4.2.1’ — 搭配日志使用
‘com.squareup.retrofit2:converter-gson:2.6.2’ — Json解析
- AndroidManifest.xml 加入网络权限
<uses-permission android:name="android.permission.INTERNET" />
- 创建数据访问接口
public interface Request_Interface {
// @POST注解的作用:采用Post方法发送网络请求
// getLoginInfo() = 接收网络请求数据的方法
// @Body BaseReq<LoginRequest> loginReq --- 输入参数,根据各自的输入参数设置
// 其中返回类型为Call<*>,*是接收数据的类(ResponseBody是直接返回json字符串)
@POST("咱们网络接口")
Call<ResponseBody> getLoginInfo(@Body BaseReq<