Retrofit2是為了Android和Java提供的一個(gè)安全的HTTP客戶(hù)端。默認(rèn)使用okhttp3
簡(jiǎn)單使用
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) {
}
});