okhttp

delay MockWebServer response

北城以北 提交于 2020-01-03 18:58:32
问题 How can I delay a Square MockWebServer HTTP response? There is a response.setBodyDelayTimeMs(...); method but this is only used in SpdySocketHandler and not for HTTP requests. 回答1: That's a bug that we OkHttp maintainers need to fix. If you report it on our issue tracker, we'll tale care of it. Or better yet, send us a pull request! 来源: https://stackoverflow.com/questions/26778379/delay-mockwebserver-response

delay MockWebServer response

孤人 提交于 2020-01-03 18:58:30
问题 How can I delay a Square MockWebServer HTTP response? There is a response.setBodyDelayTimeMs(...); method but this is only used in SpdySocketHandler and not for HTTP requests. 回答1: That's a bug that we OkHttp maintainers need to fix. If you report it on our issue tracker, we'll tale care of it. Or better yet, send us a pull request! 来源: https://stackoverflow.com/questions/26778379/delay-mockwebserver-response

How to disable retries for one connection with OkHttp?

坚强是说给别人听的谎言 提交于 2020-01-03 18:01:51
问题 I'm using OkHttp and want to disable connection retries on a particular api call. Is this the correct way to do it?: mMyGlobalClient = new OkHttpClient(); .... public void makeConnection(...) { OkHttpClient client = null; if (disableRetries) { OkHttpClient clone = mMyGlobalClient.clone(); clone.setRetryOnConnectionFailure(false); client = clone; } else { client = mMyGlobalClient; } client.newCall(...); } The idea comes from this post: https://github.com/square/okhttp/pull/1259#issue-53157152

How to disable retries for one connection with OkHttp?

末鹿安然 提交于 2020-01-03 18:01:06
问题 I'm using OkHttp and want to disable connection retries on a particular api call. Is this the correct way to do it?: mMyGlobalClient = new OkHttpClient(); .... public void makeConnection(...) { OkHttpClient client = null; if (disableRetries) { OkHttpClient clone = mMyGlobalClient.clone(); clone.setRetryOnConnectionFailure(false); client = clone; } else { client = mMyGlobalClient; } client.newCall(...); } The idea comes from this post: https://github.com/square/okhttp/pull/1259#issue-53157152

OkHttp how to set maximum connection pool size (not max idle connections)

点点圈 提交于 2020-01-03 08:53:18
问题 In OkHttp I cannot find a way to set a hard maximum connection pool size. From the documentation https://square.github.io/okhttp/3.x/okhttp/okhttp3/ConnectionPool.html it is clear that you can set a maximum idle connections, but not an overall max. That means that with high load it can grow beyond any limit. Is there a way to maximize the pool? If not, why not? 回答1: Connections are either active and held by a particular in-flight call, or idle and in the pool. Limit the total number of

OkHttp how to set maximum connection pool size (not max idle connections)

浪尽此生 提交于 2020-01-03 08:53:09
问题 In OkHttp I cannot find a way to set a hard maximum connection pool size. From the documentation https://square.github.io/okhttp/3.x/okhttp/okhttp3/ConnectionPool.html it is clear that you can set a maximum idle connections, but not an overall max. That means that with high load it can grow beyond any limit. Is there a way to maximize the pool? If not, why not? 回答1: Connections are either active and held by a particular in-flight call, or idle and in the pool. Limit the total number of

OKHTTP newCall() hangs when calling restAPI

风流意气都作罢 提交于 2020-01-02 11:18:51
问题 Trying to post to a restAPI using JAVA OKHttp. My code looks as follows: try { loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); client = new OkHttpClient.Builder() .connectTimeout(10, TimeUnit.SECONDS) .addInterceptor(loggingInterceptor) .build(); MediaType mediaType = MediaType.parse("app.lication/json"); RequestBody body = RequestBody.create(mediaType, FileUtils.readFileToString(file)); Request request = new Request.Builder()

HTTP FAILED: java.net.SocketException: Socket closed; doesn't fire up exception handling methods

假装没事ソ 提交于 2020-01-02 04:12:50
问题 I have an RxJava chain request that should release some locks onError(), or onComplete(), so, basically, what my problem is: when I set read, connect and write timeouts to my OkHttpClient, I don't get the desired behavior. I'm using Retrofit2 and OkHttp3.6.0 Here's my simplified client: OkHttpClient.Builder builder = new OkHttpClient.Builder() .readTimeout(30, TimeUnit.SECONDS) .connectTimeout(30, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS) OkHttpClient okHttpClient = builder.build(

Downloading files using OkHttp, Okio and RxJava

牧云@^-^@ 提交于 2020-01-01 19:48:21
问题 I'm trying to download files using OkHttp and writing to disk with Okio. Also I've created an rx observable for this process. It is working, however it is noticeably slower than what I had previously used (Koush's Ion library). Here's how I create the observable: public Observable<FilesWrapper> download(List<Thing> things) { return Observable.from(things) .map(thing -> { File file = new File(getExternalCacheDir() + File.separator + thing.getName()); if (!file.exists()) { Request request = new

How to use http/2 with Okhttp on Android devices?

泪湿孤枕 提交于 2020-01-01 08:30:09
问题 I'M testing a site that supports HTTP/2,like this, and I try to use okhttp to send the request: OkHttpClient okHttpClient = new OkHttpClient(); Request request = new Request.Builder() .url("https://www.google.it") .build(); okHttpClient.newCall(request).enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { e.printStackTrace(); } @Override public void onResponse(Response response) throws IOException { Log.d("TestHttp", "OkHttp-Selected-Protocol: " +