retrofit

How to handle auth0 403 error without adding specific code everywhere (Retrofit/okhttp/RxAndroid)

倖福魔咒の 提交于 2019-12-18 15:32:14
问题 I am using Auth0, which gives me a JWT (json web token) and a refreshtoken. I use this JWT in the http headers to communicate with my backend. It could happen, that the server gives me a 403 , when it decides that the JWT has expired. In this event, I can ask Auth0 to issue me a new JWT, using the refreshtoken. It means I call the Auth0 backend, pass it the refreshtoken, and it gives me a new JWT, which I can then use in my requests. My question is, how can I efficiently write this behaviour

Caused by: retrofit.RetrofitError: method POST must have a request body

邮差的信 提交于 2019-12-18 14:54:32
问题 I am using retrofit to make a post api call, I am getting the following error while trying to hit the endpoint. Caused by: rx.exceptions.OnErrorNotImplementedException: method POST must have a request body. at rx.Observable$30.onError(Observable.java:7334) at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:154) at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:111) at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:197) at rx

How can I return value from onResponse of Retrofit v2

别等时光非礼了梦想. 提交于 2019-12-18 13:37:41
问题 I want to return a string value from my function. But I do not know how to handle it? I tried final one-array solution but it did not work out. Here is my code: public String revealCourtPlace(String courtID) { BaseService.getInstance().getUniqueCourt(Session.getToken(),courtID).enqueue(new Callback<JsonObject>() { @Override public void onResponse(Call<JsonObject> call, Response<JsonObject> response) { JsonObject object = response.body(); boolean success = object.get("success").getAsBoolean();

Retrofit 2 + Rxjava handling error

ⅰ亾dé卋堺 提交于 2019-12-18 13:16:32
问题 So i already receive a token from the Json when the login is made without problems, and receive the hash But when the response from the server is a error, i cannot get the Json message ({message:"Error : wrong email} " because in the onError we only get as argument a Throwable and not a model class like in on how can i get a json message from server onError?? final Observable<TokenResponse> observable = Service.login(userCredentials); observable.subscribeOn(Schedulers.io()) .observeOn

Retrofit 2 not sending data when ProGuard is enabled

萝らか妹 提交于 2019-12-18 12:12:19
问题 I try to login my users using Retrofit 2. (Basically a GET to the login URL with a basic header) It works well but once I ProGuard it, the Header Authorization is not sent anymore. (See log outputs) Sample code : User Model : public interface UserService { @GET(GET_LOGIN) Observable<User> login(@Header("Authorization") String basic); } Login Activity : public void onClick(View v) { mRetrofit.create(UserService.class) .login(Credentials.basic(email, password)) .subscribeOn(Schedulers.io())

Retrofit: what is different between @Field and @Body

人盡茶涼 提交于 2019-12-18 11:46:21
问题 In some post request, I don't know when to use @Field, when to use @Body. Like whats the difference between: @POST("users/register") Call<String> register(@Body RequestBody registerRequest); and: @POST("users/register") Call<String> register(@Field String id, @Field String pass); Can I use @Body instead of @Field, and reverse ? If not, why ? And how to know this case use @Body, other case use @Field ? Can you please give me some case and explain, thank you. 回答1: @Body – Sends Java objects as

Is it possible to show progress bar when download via Retrofit 2 Asynchronous?

淺唱寂寞╮ 提交于 2019-12-18 11:30:28
问题 @Streaming @GET Call<ResponseBody> downloadSong(@Url String url); Above code is used to download file asynchronously using retrofit. I want get the progress of download, if there any possibility of pause/ resume please answer that too 回答1: At last I got my answer. For that we need to use rxjava along with retrofit. DownloadProgressListener.java public interface DownloadProgressListener { void update(long bytesRead, long contentLength, boolean done); } DownloadProgressResponseBody.java public

Is Retrofit+Okhttp using httpCaching as a default in Android?

房东的猫 提交于 2019-12-18 10:56:25
问题 I use retrofit and okhttp in one of our applications. I can't really find a good explanation for the default behaviour of Retrofit. If Okhttp is on the class path it will be automatically used. But as far as I can see it the default HttpResponseCache is null. Do I need to explicitly enable caching with Retrofit and Okhttp? 回答1: You should manually create your OkHttpClient and configure it how you like. In this case you should install a cache. Once you have that create an OkClient and pass it

Perform requests with Retrofit inside custom Runnable

こ雲淡風輕ζ 提交于 2019-12-18 10:36:22
问题 I am migrating from Volley to a custom implementation using Retrofit , but I'm trying to add to my implementation some of the Volley features that I liked, for example RequestQueue.cancel(String tag) If the Request has the requested tag, then it's canceled by setting a boolean value, mCanceled , to true. The run method checks this value and returns if it's true. To be able to reproduce this with Retrofit I should be able to use my custom class implementing Runnable instead of the default one,

Call another rest api from my server in Spring-Boot

六眼飞鱼酱① 提交于 2019-12-18 10:24:09
问题 I want to call another web-api from my backend on a specific request of user. For example, I want to call Google FCM send message api to send a message to a specific user on an event. Does Retrofit have any method to achieve this? If not, how I can do that? 回答1: This website has some nice examples for using spring's RestTemplate. Here is a code example of how it can work to get a simple object: private static void getEmployees() { final String uri = "http://localhost:8080/springrestexample