okhttp3

OkHttp Authenticator sometimes does not call authenticate on HTTP 401

流过昼夜 提交于 2019-12-24 08:25:32
问题 I have an issue that OkHttp 's Authenticator does not call the authenticate method in some cases of HTTP 401 errors. Interceptors are always called, but authenticator is sometimes called and sometimes not. Once it does not call it it will not call it for several minutes and all network calls will fail with HTTP 401. Then after 5-6 minutes it will "unstuck" and call the authenticate method again. I use it for refreshing token. If the token expiration is set to one hour, there are no issues,

java.lang.NoSuchMethodError - okhttp3 (Android)

最后都变了- 提交于 2019-12-24 06:47:35
问题 My app keeps crashing. Can't figure out where the issue is. I'm not even using okttp3 library. Currently, I'm only using retrofit 1.9 and otto 1.3.8 java.lang.NoSuchMethodError: No virtual method callEnqueue(Lokhttp3/Call;Lokhttp3/Callback;Z)V in class Lokhttp3/internal/Internal; or its super classes (declaration of 'okhttp3.internal.Internal' appears in /data/app/com.myproj.sample-2/base.apk) at okhttp3.ws.WebSocketCall.enqueue(WebSocketCall.java:108) at io.socket.engineio.client.transports

Best Scope in Dagger2 for Okhttp3 with dynamic Interceptors

萝らか妹 提交于 2019-12-23 20:03:12
问题 How would the scope work with Auth Tokens? I cannot create my Retrofit instance until I can add an interceptor that signs it with my auth token. Therefore, I would like to create Retrofit when the auth tokens are available (after sign-in). How do I get scope working correctly in this situation? Thanks a lot! 回答1: There is no best way of doing this, and it might also depend on how often you change / recreate your Retrofit instances. What's better, or which better fits your use case depends

RxJava, Proguard and sun.misc.Unsafe

本小妞迷上赌 提交于 2019-12-23 15:49:20
问题 I have problems with RxJava (1.1.0) when using Proguard . I didn't change RxJava version nor its .pro file, but after updating OkHttp I couldn't compile using Proguard because I had warnings about sun.misc.Unsafe not being present. rxJava.pro -keep class rx.schedulers.Schedulers { public static <methods>; } -keep class rx.schedulers.ImmediateScheduler { public <methods>; } -keep class rx.schedulers.TestScheduler { public <methods>; } -keep class rx.schedulers.Schedulers { public static **

Okhttp3 set timeout is useless

蹲街弑〆低调 提交于 2019-12-23 10:49:40
问题 OkHttpClient client; client = new OkHttpClient.Builder() .connectTimeout(5, TimeUnit.SECONDS) .writeTimeout(5, TimeUnit.SECONDS) .readTimeout(5, TimeUnit.SECONDS) .build(); Request request22 = new Request.Builder() .url("http://www.goo.com/") .build(); Utils.myLog("-begin-"); Response response = null; try { response = client.newCall(request22).execute(); if (response.isSuccessful()) { Utils.myLog("-donw-"); } } catch (Exception e) { e.printStackTrace(); Utils.myLog("-error-" + e.toString());

OkHttp and Retrofit, refresh token with concurrent requests

亡梦爱人 提交于 2019-12-23 08:17:07
问题 In my application I implemented Retrofit to call WebServices and I'm using OkHttp to use Interceptor and Authenticator. Some requests need token, and I have implemented Authenticator interface to handle the refresh (following the official documentation). But I have the following issue : time to time in my app I have to call more than one request at once. Because of that, for one of them I will have the 401 error. Here is my code for request calls : public static <S> S

Retrofit Adding tag to the original request object

此生再无相见时 提交于 2019-12-23 07:57:21
问题 I'm trying to solve a problem where I'll be making a couple of asynchronous calls and based on the original request, I'm performing a task. To solve this issue, I'm trying to add a TAG to each request and then on successful response, I can get the tag and take action based on the tag. Here, I'm using TAG only to identify the original request. Problem Before calling the enqueue method, I'm setting the tag to the original request. But when I get the response in the successful callback, I'm

android retrofit2 could not add header (415 error code)

一笑奈何 提交于 2019-12-23 04:55:10
问题 I'm trying to access ticket data via skyscanner api and pass it to my view, but I cannot accomplish that, because I get 415 error code I'm using retrofit2 and adding header programmatically. My interface looks like this: public interface GetFlightDetails { @POST("apiservices/pricing/v1.0/") Call<TicketData> getFlightList(@Query("apiKey") String apiKey, @Query("country") String country, @Query("currency") String currency, @Query("locale") String locale, @Query("originPlace") String originPlace

okhttp 3: how to decompress gzip/deflate response manually using Java/Android

北慕城南 提交于 2019-12-22 10:31:52
问题 I know that okhttp3 library by default it adds the header Accept-Encoding: gzip and decodes the response automatically for us. The problem I'm dealing with a host that only accepts a header like: Accept-Encoding: gzip, deflate if I don't add the deflate part it fails. Now when I manually add that header to okhttp client, the library doesn't do the decompression anymore for me. I've tried multiple solutions to take the response and try to manually decompress that but I've always ended up with

okhttp3 RequestBody in Kotlin

拈花ヽ惹草 提交于 2019-12-22 06:09:21
问题 I want to send a request body like this : How I send this ? I will send it as a class ? "email":{ "emailto":"foo@bar.com", "emailfrom":"foo@bar.com", "emailcc":"foo@bar.com", "emailbcc":"foo@bar.com", "emailsubject":"Subject", "emailtag":"Information", "emailtextbody":"---", "attachments":[] } val formBody = FormBody.Builder() .add("email", "Your message") .build() val request = Request.Builder() .url(url) .post(formBody) .addHeader("_Token","") .addHeader("Content-Type","application/json")