Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Okhttp how to send the non - keepalive request #2031

Closed
jinpu opened this issue Nov 24, 2015 · 4 comments
Closed

Okhttp how to send the non - keepalive request #2031

jinpu opened this issue Nov 24, 2015 · 4 comments

Comments

@jinpu
Copy link

jinpu commented Nov 24, 2015

@swankjesse I want to use okhttp sends a non - keepalive request, my understanding is okhttp default sends a keepalive request, but I am not sure that's the case, how should I set the non - keepalive?

@asgmojtaba
Copy link

you can set custom connection pool with zero for maxIdleConnection parameter

okHttpClient.setConnectionPool(new ConnectionPool(0, 0));

note: this is just use case you must declare your connection pool as singleton

@swankjesse
Copy link
Collaborator

Use the following header: Connection: close.

@jinpu
Copy link
Author

jinpu commented Nov 25, 2015

Yes, according to your method is ok, thank you!

@jinpu
Copy link
Author

jinpu commented Nov 25, 2015

@swankjesse I use the code sends the request, see is non - keepalive from the server end, but the reponse header like this:
{"OkHttp-Selected-Protocol":"http/1.1","content-type":"text/plain","accept-ranges":"bytes","Content-Length":"6","Server":"h2o/1.6.0-alpha1","Connection":"keep-alive"}
I'm not sure that my programe is right? Please give some suggest,thanks!

 client_h1 = new OkHttpClient();
 client_h1.setProtocols(Arrays.asList(Protocol.HTTP_1_1)).setConnectionPool(new ConnectionPool(100,10000));
        for (int i = 0; i < request_times; ++i) {
            request = new Request.Builder().url(Url)
                                .addHeader("Connection","keep-alive")
                                .build(); 
            response = client_h1.newCall(request).execute();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants