Retrofit的使用

github网址:https://github.com/square/retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.okhttp3:okhttp:3.14.9'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'

//自定一个请求类接口retrofitInterface
    @POST(Constants.Login)
Call<LoginBean> loginPost(@Body UserBean userBean);

//设置baseUrl

public static Retrofit getRetrofitObj() {
    return new Retrofit.Builder()
.baseUrl(Constants.IP)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
Retrofit retrofit = getRetrofitObj();
retrofitInterface login = retrofit.create(retrofitInterface.class);
Call<LoginBean> call = login.loginPost(new UserBean(name, pw));
call.enqueue(...)


posted @ 2020-06-08 17:37  码弄  阅读(404)  评论(0编辑  收藏  举报