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(...)
最简单的教养,就是适当地回避别人的难堪。