retrofit

Retrofit POST request w/ Basic HTTP Authentication: “Cannot retry streamed HTTP body”

妖精的绣舞 提交于 2019-12-18 10:20:09
问题 I'm using Retrofit to do a basic POST request, and I'm providing a basic @Body for the request. @POST("/rest/v1/auth/login") LoginResponse login(@Body LoginRequest loginRequest); When I'm building the interface for Retrofit I'm providing my own custom OkHttpClient, and all that I'm doing to it is adding my own custom authentication: @Provides @Singleton public Client providesClient() { OkHttpClient httpClient = new OkHttpClient(); httpClient.setAuthenticator(new OkAuthenticator() { @Override

Retrofit/Rxjava and session-based services

心不动则不痛 提交于 2019-12-18 10:19:19
问题 I'm implementing session-based services. All requests have to be subscribed with a cookie session param, which in turn is retrieved with separate rest api. So the basic workflow would be to get the session cookie and proceed querying the services. Occasionally the cookie would expire and it would lead to another session cookie request. I'm trying to make client code session-agnostic, so that it doesn't have to worry about maintaining session, but rather I want it to be hidden inside services

Retrofit with Rxjava Schedulers.newThread() vs Schedulers.io()

假装没事ソ 提交于 2019-12-18 10:15:02
问题 What are the benefits to use Schedulers.newThread() vs Schedulers.io() in Retrofit network request. I have seen many examples that use io() , but I want to understand why. Example situation: observable.onErrorResumeNext(refreshTokenAndRetry(observable)) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread())... vs observable.onErrorResumeNext(refreshTokenAndRetry(observable)) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread())... One of the reasons

java.util.LinkedHashMap cannot be cast to DataList

送分小仙女□ 提交于 2019-12-18 08:49:34
问题 I am trying to implement the server connections with retrofit library. Everything seems fine but when I receive the data on success callback it crashes with the below exception. java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to aandroid.com.retrofitframework.requestData.DataList at cuiserve.com.volleyframework.activity.RetrofitActivity$1.onDataReceived(RetrofitActivity.java:18) at cuiserve.com.volleyframework.httpConnection.ConnectionHelper.success(ConnectionHelper.java

GSON: JSON deserialization to variable type (List/String)

爱⌒轻易说出口 提交于 2019-12-18 07:15:11
问题 At this point it's already an old question and I've probably read every related topic on SO. But to the point. I need some advice or correction maybe? For some reason we have generatable Jsons of 2 types: {"data": {"id": "value"}} and {"data":[{"id": "value"}]} Object and Array. There are also other params but they doesn't matter here. "id" is differ for every request. Sometimes it's userId, portfolioId etc. So I get "id" and pass it to related var. For a long time I was working with the

GSON: JSON deserialization to variable type (List/String)

空扰寡人 提交于 2019-12-18 07:15:10
问题 At this point it's already an old question and I've probably read every related topic on SO. But to the point. I need some advice or correction maybe? For some reason we have generatable Jsons of 2 types: {"data": {"id": "value"}} and {"data":[{"id": "value"}]} Object and Array. There are also other params but they doesn't matter here. "id" is differ for every request. Sometimes it's userId, portfolioId etc. So I get "id" and pass it to related var. For a long time I was working with the

Consuming One-Shot ResponseBody from Okhttp causes issues with Retrofit

*爱你&永不变心* 提交于 2019-12-18 06:17:30
问题 I am using an Retrofit with an Okhttp interceptor in order to detect if my oauth token has expired. If the token has expired, I want to request a new token, try the request again, then send that response to Retrofit. Here is my interceptor class: public class CustomInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); // try the request Response response = chain.proceed(request); if (response.body().string

Retrofit encoding special characters

試著忘記壹切 提交于 2019-12-18 05:58:32
问题 I am using retrofit with gson instead of android since its faster and more secure. The problem is that retrofit is encoding special characters like = and ? , and the url I'm using cannot decode these characters. This is my code: api class: public interface placeApi { @GET("/{id}") public void getFeed(@Path("id") TypedString id, Callback<PlaceModel> response); } Main class: String url = "http://api.beirut.com/BeirutProfile.php?"; String next = "profileid=111"; //Creating adapter for retrofit

Retrofit encoding special characters

為{幸葍}努か 提交于 2019-12-18 05:58:12
问题 I am using retrofit with gson instead of android since its faster and more secure. The problem is that retrofit is encoding special characters like = and ? , and the url I'm using cannot decode these characters. This is my code: api class: public interface placeApi { @GET("/{id}") public void getFeed(@Path("id") TypedString id, Callback<PlaceModel> response); } Main class: String url = "http://api.beirut.com/BeirutProfile.php?"; String next = "profileid=111"; //Creating adapter for retrofit

How to get raw response and request using Retrofit 2.0

拟墨画扇 提交于 2019-12-18 04:35:22
问题 I am trying to get the raw response using Retrofit2.0.2. So far I tried to print the response using following line of code but it prints the address and not the exact response body. Log.i("RAW MESSAGE",response.body().toString()); compile 'com.squareup.retrofit2:retrofit:2.0.2' Retrofit retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); GitApi gitApi = retrofit.create(GitApi.class); Call<Addresses> call = gitApi.getFeed(user);