
RestTemplate provides higher level methods that correspond to each of the six main HTTP methods. It is supported on Android 2.3 (Gingerbread) and newer, however in order to use it, you must include the OkHttp dependency in your project.Ĭompile(':okhttp-urlconnection:$okHttpVersion') RestTemplate can be configured to use OkHttpRequestFactory through the RestTemplate constructor or by setting the requestFactory property. HttpClient 4.3 has a considerable number of bug fixes and improvements over the native HttpClient 4.0 included within Android.Ĭompile(':httpclient-android:$httpClientVersion')Īn additional ClientHttpRequestFactory based on OkHttp is available as an alternative to the two native clients. If Spring for Android detects HttpClient 4.3, then it will automatically configure it as the default ClientHttpRequestFactory. HttpClient 4.3 for Android is compatible with all versions of Android, and may be utilized as an alternative to the native clients by simply including the dependency in your project.

Spring for Android also includes support for third-party HTTP client libraries.

To utilize a specific ClientHttpRequestFactory you must either pass a new instance into the RestTemplate constructor, or call setRequestFactory(ClientHttpRequestFactory requestFactory) on an existing RestTemplate instance.

Based on this recommendation RestTemplate checks the version of Android on which your app is running and uses the appropriate ClientHttpRequestFactory. Google recommends to use the J2SE facilities on Android 2.3 (Gingerbread) and newer, while previous versions should use the HttpComponents HttpClient. The default ClientHttpRequestFactory used when you create a new RestTemplate instance differs based on the version of Android on which your application is running. Support for native HttpClient 4.0 is deprecated in favor of the Android port of HttpClient 4.3. The standard JS2SE facilities are made available through SimpleClientHttpRequestFactory, while the HttpClient can be utilized via HttpComponentsAndroidClientHttpRequestFactory. There are two native HTTP clients available on Android, the standard J2SE facilities, and the HttpComponents HttpClient. RestTemplate provides an abstraction for making RESTful HTTP requests, and internally, RestTemplate utilizes a native Android HTTP client library for those requests.

Establishing an OAuth 1.0a connection 3.4.5. Available Message Converters ByteArrayHttpMessageConverter FormHttpMessageConverter AllEncompassingFormHttpMessageConverter ResourceHttpMessageConverter SourceHttpMessageConverter StringHttpMessageConverter SimpleXmlHttpMessageConverter MappingJackson2HttpMessageConverter GsonHttpMessageConverter 2.7.
