Retrofit2(1):基本介绍

2017-10-10  本文已影响0人  hiandg

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) {

}

});

上一篇 下一篇

猜你喜欢

热点阅读