前方高能--Retrofit

Retrofit是一款为Android和Java设计的类型安全的REST客户端,它提供了方便的API声明、请求方法、URL操作、动态更新请求头等功能。支持同步、异步和RxJava的观察者模式执行HTTP请求,并能将响应自动转换为指定类型,如JSON。
摘要由CSDN通过智能技术生成

Retrofit

A type-safe REST client for Android and Java


Android中非常有名的网络框架
官网 :http://square.github.io/retrofit/
参考项目: http://square.github.io/okhttp/
Android 示例项目: https://github.com/goodev/RetrofitDemo


Retrofit vs Volley
http://instructure.github.io/blog/2013/12/09/volley-vs-retrofit/
提取一张图片
这里写图片描述

//API
public interface ApiService {
    @GET("/jobs")
    public void getJobs(Callback<Data> callback);
}
//RestClient
public class RestClient {

    private static final String BASE_URL = "https://yourapi.host.com";
    private ApiService apiService;

    public RestClient() {
        Gson gson = new GsonBuilder()
                .registerTypeAdapterFactory(new ItemTypeAdapterFactory())
                .setDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSS'Z'")
                .create();

        RestAdapter restAdapter = new RestAdapter.Builder()
                .setLogLevel(RestAdapter.LogLevel.FULL)
                .setEndpoint(BASE_URL) 
                .setConverter(new GsonConverter(gson))
                .setRequestInterceptor(new SessionRequestInterceptor())
                .setClient(new OkClient(MySSLTrust.getUnsafeOkHttpClient()))
                .build();

        apiService = restAdapter.create(ApiService.class);
    }

    public ApiService getApiService() {
        return apiService;
    }
}
<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值