I am using Retrofit 1.9 to obtain a XML.
public class ServicioConexionRetrofitXML {
public static final String API_BASE_URL = new GestorPreferencias().getPreferencias().getHost();
public static final long tiempoMaximoRespuestaSegundos = 60;
public static final long tiempoMaximoLecturaSegundos = 100;
public static final OkHttpClient clienteOkHttp = new OkHttpClient();
private static RestAdapter.Builder builder = new RestAdapter.Builder().
setEndpoint(API_BASE_URL).
setClient(new OkClient(clienteOkHttp)).setConverter(new SimpleXMLConverter());
public static <S> S createService(Class<S> serviceClass) {
clienteOkHttp.setConnectTimeout(tiempoMaximoRespuestaSegundos, TimeUnit.SECONDS);
clienteOkHttp.setReadTimeout(tiempoMaximoLecturaSegundos, TimeUnit.SECONDS);
RestAdapter adapter = builder.build();
return adapter.create(serviceClass);
}
}
If you are using Retrofit 1.9.0 and okhttp 2.6.0, add to your Gradle file.
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp:2.6.0'
// LibrerÃa de retrofit para XML converter (Simple) Se excluyen grupos para que no entre
// en conflicto.
compile('com.squareup.retrofit:converter-simplexml:1.9.0') {
exclude group: 'xpp3', module: 'xpp3'
exclude group: 'stax', module: 'stax-api'
exclude group: 'stax', module: 'stax'
}
Note: If you need to fetch a JSON, just remove from code above.
.setConverter(new SimpleXMLConverter())