Android retrofit2
首先在build.gradle添加依赖
implementation ‘com.squareup.retrofit2:retrofit:2.6.1’
implementation ‘com.squareup.retrofit2:converter-gson:2.6.1’
因为这里之后的网络请求接口一般传回来的数据都是json的数据
通过andorid gson来进行数据的转换
也就要引入
implementation’com.google.code.gson:gson:2.8.5’
BASE_URL你所使用的接口
然后建立你的Service接口
这里@GET()里的value代表的是你所要使用的接口
切记开始不能有/
然后你可以通过@Headers来添加头
也就是在方法中使用@Query来携带数据
然后在使用enqueue来发送请求
android开发 retrofit2的使用
最新推荐文章于 2025-04-01 15:49:35 发布