HttpURLConnection - keep-alive

E

erjdriver

i'm using HttpURLConnection to connect to an http
server and get pages - everything works.

when the server responds with Connection: Keep-alive,
i'd like to send the next http GET/POST request
using the current connection (w/o closing it).

there doesn't seem to be a way of doing this.

any help?
 
F

Frank Cisco

erjdriver said:
i'm using HttpURLConnection to connect to an http
server and get pages - everything works.

when the server responds with Connection: Keep-alive,
i'd like to send the next http GET/POST request
using the current connection (w/o closing it).

there doesn't seem to be a way of doing this.

any help?

I believe HttpURLConnection does this automatically
 
E

erjdriver

I believe HttpURLConnection does this automatically

yes the class abstracts quite a bit of HTTP protocol - that's nice.

but if i see a Keep-Alive header and would like to
send the next request (e.g. a GET) how do i do it.

i.e. how do i specify the URI (the host has to be the same etc.)
and do i call connect() again.
 
F

Frank Cisco

I believe HttpURLConnection does this automatically
yes the class abstracts quite a bit of HTTP protocol - that's nice.
but if i see a Keep-Alive header and would like to
send the next request (e.g. a GET) how do i do it.
i.e. how do i specify the URI (the host has to be the same etc.)
and do i call connect() again.


Use sockets if really want more control, but HttpURLConnection works well if
you just set another URL path (afaik) on it. All a bit cryptic but he's the
javadoc:

"Each HttpURLConnection instance is used to make a single request [[but the
underlying network connection to the HTTP server may be transparently shared
by other instances]]. Calling the close() methods on the InputStream or
OutputStream of an HttpURLConnection after a request may free network
resources associated with this instance but has no effect on any shared
persistent connection. Calling the disconnect() method may close the
underlying socket if a persistent connection is otherwise idle at that
time."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top