本文主要是介绍前方高能--Retrofit,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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;}
}
<
这篇关于前方高能--Retrofit的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!