Retrofit2是为了Android和Java提供的一个安全的HTTP客户端。默认使用okhttp3
简单使用
Retrofit retrofit =newRetrofit.Builder()
.baseUrl("https://192.168.1.189:5000/")
.build();
api= retrofit.create(Api.class);
Call userInfo =api.getUserInfo();
userInfo.enqueue(newCallback() {
@Override
public voidonResponse(Call call, Response response) {
try{
String result = response.body().string();
}catch(IOException e) {
e.printStackTrace();
}
}
@Override
public voidonFailure(Call call, Throwable t) {
}
});
网友评论