okhttp3

How to change timeout for a request in okhttp

喜欢而已 提交于 2021-02-18 11:00:39
问题 In general we set timeout for the okHttp client and we use single instance of that client. So, we can't change the timeout for that client once it's generated. How to change the timeout for a particular request ?? Is there anyway to do it without creating new client?? It's very common that some calls take more time atleast 1/2 per app, which needs more timeout than others. it would be great if request can override the default timeout. 回答1: In 3.9 it is possible to set this per request in an

How to change timeout for a request in okhttp

巧了我就是萌 提交于 2021-02-18 11:00:28
问题 In general we set timeout for the okHttp client and we use single instance of that client. So, we can't change the timeout for that client once it's generated. How to change the timeout for a particular request ?? Is there anyway to do it without creating new client?? It's very common that some calls take more time atleast 1/2 per app, which needs more timeout than others. it would be great if request can override the default timeout. 回答1: In 3.9 it is possible to set this per request in an

How to change timeout for a request in okhttp

£可爱£侵袭症+ 提交于 2021-02-18 11:00:28
问题 In general we set timeout for the okHttp client and we use single instance of that client. So, we can't change the timeout for that client once it's generated. How to change the timeout for a particular request ?? Is there anyway to do it without creating new client?? It's very common that some calls take more time atleast 1/2 per app, which needs more timeout than others. it would be great if request can override the default timeout. 回答1: In 3.9 it is possible to set this per request in an

HTTP FAILED: java.io.IOException: unexpected end of stream exception while making https request

好久不见. 提交于 2021-02-16 20:05:02
问题 We are previously using http apis and now we have migrated to https, with same code we are facing the exception HTTP FAILED: java.io.IOException: unexpected end of stream (this is for some device and for some network calls). We are using the OkHttp and Retrofit from android app. Below is our code @Provides @ApplicationScope OkHttpClient provideOkHttpClientV2( HttpLoggingInterceptor logging, Interceptor headerInterceptor) { OkHttpClient.Builder builder = new OkHttpClient.Builder(); //Removed

HTTP FAILED: java.io.IOException: unexpected end of stream exception while making https request

て烟熏妆下的殇ゞ 提交于 2021-02-16 20:04:23
问题 We are previously using http apis and now we have migrated to https, with same code we are facing the exception HTTP FAILED: java.io.IOException: unexpected end of stream (this is for some device and for some network calls). We are using the OkHttp and Retrofit from android app. Below is our code @Provides @ApplicationScope OkHttpClient provideOkHttpClientV2( HttpLoggingInterceptor logging, Interceptor headerInterceptor) { OkHttpClient.Builder builder = new OkHttpClient.Builder(); //Removed

Retrofit / OkHttp3 400 Error Body Empty

吃可爱长大的小学妹 提交于 2021-02-08 13:32:04
问题 I am using Retrofit 2 in my Android project. When I hit an API endpoint using a GET method and it returns a 400 level error I can see the error content when I use an HttpLoggingInterceptor, but when I get to the Retrofit OnResponse callback the error body's string is empty. I can see that there is a body to the error, but I can't seem to pull that body when in the context of the Retrofit callback. Is there a way to ensure the body is accessible there? Thanks, Adam Edit: The response I see

Is it possible to throttle bandwidth when using OkHttp?

不羁岁月 提交于 2021-02-07 14:47:29
问题 Is it possible when using OkHttp to throttle the bandwidth? (possibly using a network interceptor). 回答1: You can make it work in two ways: Send request and read stream manually, and throttle while reading there. Add an Interceptor. Using OkHttp the best way is Interceptor. There are also a few simple steps: To inherit the Interceptor interface. To inherit the ResponseBody class. In custom ResponceBody override fun source(): BufferedSource needs to return the BandwidthSource's buffer. Example

Is it possible to throttle bandwidth when using OkHttp?

人走茶凉 提交于 2021-02-07 14:47:29
问题 Is it possible when using OkHttp to throttle the bandwidth? (possibly using a network interceptor). 回答1: You can make it work in two ways: Send request and read stream manually, and throttle while reading there. Add an Interceptor. Using OkHttp the best way is Interceptor. There are also a few simple steps: To inherit the Interceptor interface. To inherit the ResponseBody class. In custom ResponceBody override fun source(): BufferedSource needs to return the BandwidthSource's buffer. Example

Is it possible to throttle bandwidth when using OkHttp?

我与影子孤独终老i 提交于 2021-02-07 14:46:41
问题 Is it possible when using OkHttp to throttle the bandwidth? (possibly using a network interceptor). 回答1: You can make it work in two ways: Send request and read stream manually, and throttle while reading there. Add an Interceptor. Using OkHttp the best way is Interceptor. There are also a few simple steps: To inherit the Interceptor interface. To inherit the ResponseBody class. In custom ResponceBody override fun source(): BufferedSource needs to return the BandwidthSource's buffer. Example

OkHttp connection leak log line even when OkHttp is not a dependency

醉酒当歌 提交于 2021-02-05 06:13:23
问题 I keep seeing the following log line in Logcat while I use my app: 19098-19147/<package> W/OkHttpClient: A connection to <my server> was leaked. Did you forget to close a response body? I did some research on this bug and found that it can happen when you do things like forget to close a response body in an interceptor. I commented out all of interceptors to see if one of them was causing this issue, but I still saw the log line. I eventually commented out all uses of OkHttp and I still