okhttp3

okhttp Interceptors to intercept when internet is disabled

孤街浪徒 提交于 2019-12-11 18:09:38
问题 I am working on network module where it should provide offline data where I am fetching previously stored JSON response from local db and building response and returning to the application. All this is happening in my okhttp Interceptor at application level. I know I could have checked for n/w availability with ConnectivityManager Every time I tried with n/w disabled or changing server false server URL for testing, Debugger just disappears call to chain.proceed(request) Please note I knew I

How to make an Okhttp Request with “Content-type:application/x-www-form-urlencoded”?

半腔热情 提交于 2019-12-11 17:49:06
问题 I have an api requirement of Sending following parameters in header- Content-Type - application/x-www-form-urlencoded authKey- (Session token) and following parameters in body(form day i.e key-value pair) storeId -1 type -Product CategoryId -324 But whenever I hit this api, I am always getting 401(UnAuthorized) error. I have tried using MultipartRequest body and formBody, I know this is nothing to do with the body(Its the header where I need to send the Content-Type and authKey). Below is my

How do I do multiplexing on OkHttp?

可紊 提交于 2019-12-11 16:01:38
问题 I see some older questions about using SPDY (though the code has changed significantly since then), but no insights into how to properly leverage multiplexing and/or pipelining in OkHttp. I've gone through all the examples and have yet to see anything specifically referring to this. Is this something that is automatically done? 回答1: It’s automatic. If you have a server that supports HTTP/2, and a client that supports HTTP/2, it’ll do the right thing. 来源: https://stackoverflow.com/questions

Strange error with GLIDE while loading image on production build

北城以北 提交于 2019-12-11 15:48:08
问题 After applying ProGuard on my production app. We are facing the following error on loading images from URLs E/vw: Glide failed to load image with exception: UNABLE TO LOAD PUBLICSUFFIXES.GZ RESOURCE FROM THE CLASSPATH. java.lang.IllegalStateException: Unable to load publicsuffixes.gz resource from the classpath. Finally, we tried keeping the whole Glide sources in the progaurd configuration with the following command -keep public class * implements com.bumptech.glide.module.GlideModule -keep

How to create simple okhttp3 websocket connection?

一个人想着一个人 提交于 2019-12-11 07:35:49
问题 Can someone please show me an example on how to establish the connection to the wss:// address with specific Authorization header, using okhttp3 okhttp-ws library? All I have is the url of WS server and Authorization string token. Later, I must be able to send request to that connection, listen to upcoming data from WS server and than close connection. I have a difficulties with this new to me WS world, always been working only with REST (with okhttp3 too) 回答1: So generally this sample is

OkHttp: A connection to http://example.com/ was leaked. Did you forget to close a response body?

断了今生、忘了曾经 提交于 2019-12-11 05:44:42
问题 This error message of OkHttp v3.4.1 has already been discussed a few times, and each time I read about it, people were not closing the response body: WARNING: A connection to http://www.example.com/ was leaked. Did you forget to close a response body? But my code reads like this: private String executeRequest(Request request) throws IOException { Response response = httpClient.newCall(request).execute(); try (ResponseBody responseBody = response.body()) { String string = responseBody.string()

NoClassDefFoundError: Square Logging Interceptor v3.12.0

蹲街弑〆低调 提交于 2019-12-11 04:48:44
问题 Issue After adding the Square Okhttp Logging Interceptor library to my Kotlin app I am experiencing the following error which I think may be due to a Guava dependency conflict. I've filed an issue in Square's library as well. Error Exception in thread "Timer-0" java.lang.NoClassDefFoundError: okhttp3/logging/HttpLoggingInterceptor at utils.Retrofit.retrofitBuilder(Retrofit.kt:28) at utils.Retrofit.<clinit>(Retrofit.kt:19) at content.ContentRequestsKt.getEventRegistryContent(ContentRequests.kt

Okhttp not selecting http2 on Android 7.0

混江龙づ霸主 提交于 2019-12-11 04:39:53
问题 I am trying to make an HTTP request to the following domain (http2 enabled) on a device running on Android 7.0. The code i use is as follows: Request request = new Request.Builder() .url("https://http2.akamai.com/") .build(); response = okHttpClient.newCall(request).execute(); statusCode = response.code(); As I notice in the response object, the protocol used by okHttp is HTTP 1.1 The behavior of the okhttp client is random, at one time I was able to see the protocol as h2 but then repeating

okhttp3 maximum connection timeout

余生长醉 提交于 2019-12-11 03:33:17
问题 I need help with timeouts in okhttp3. I configured the maximum connect, read and write timeout to 4 minutes like that: OkHttpClient client = new OkHttpClient.Builder() .connectTimeout(totalSeconds, TimeUnit.SECONDS) .writeTimeout(totalSeconds, TimeUnit.SECONDS) .readTimeout(totalSeconds, TimeUnit.SECONDS) .build(); totalSeconds = 240.000 but throws exception SocketTimeoutException in 2 minutes. Please someone have been in this situation? how can i solve it? Thanks in advance 来源: https:/

The Context parameter passage problem in android [Interceptor]

萝らか妹 提交于 2019-12-11 02:55:28
问题 I'm new in android development and used to develop in JavaScript. A common practice there is to implement an interceptor to add Authorization header. In my current application is not different. In this new world to me, SharedPreferences is quite equivalent to LocalStorage . But to access the first one I have to use a Context . Here is my problem: to get a token, stored in SharedPreferences , being inside the intercept method, I must pass a Context to the Interceptor , but the flow 'til there