HttpWebRequest keepalive

C

Cliff Harris

I am trying to automate a series of form posts on a website. This site
requires that my session be kept alive through successive posts (it
basically tracks me by a sessionid, and if I get a new connection each time,
I get a new sessionid).
An HttpWebRequest object has a KeepAlive property that is, by default, set
to true. I have been unsuccessful in finding adequate documentation about
this. Most people seem to not want to keep the connection alive, so they
set the property to false, and is thus, the exact opposite of what I am
looking for.
What I am wondering is how I go about making successive requests with the
same connection? If KeepAlive is set to true, does the object just
automatically reuse a connection to a server if it exists? I cannnot seem
to find a way to "reuse" my webrequest object, and have to create a new one
each time.
What would be the method to create successive Requests/Responses to a server
on the same connection?

Thanks,
-Cliff
 
J

Joerg Jooss

Cliff Harris said:
I am trying to automate a series of form posts on a website. This
site requires that my session be kept alive through successive posts
(it basically tracks me by a sessionid, and if I get a new
connection each time, I get a new sessionid).
An HttpWebRequest object has a KeepAlive property that is, by
default, set to true. I have been unsuccessful in finding adequate
documentation about this. Most people seem to not want to keep the
connection alive, so they set the property to false, and is thus,
the exact opposite of what I am looking for.
What I am wondering is how I go about making successive requests
with the same connection? If KeepAlive is set to true, does the
object just automatically reuse a connection to a server if it
exists? I cannnot seem to find a way to "reuse" my webrequest
object, and have to create a new one each time.
What would be the method to create successive Requests/Responses to
a server on the same connection?

Cliff,

sessions have nothing to do with persistent connections (known as "keep-
alive" connections in HTTP 1.0). Keep-alive connections are a mere
performance optimization at TCP level to reduce the overhead of opening
new a TCP connection for each new HTTP request.

For what you want to achieve, you'll need to resubmit the session id you
mentioned with each request. How that can be achieved depends on how
sessions are implemented by the web application -- could be cookies, URL
rewriting, or hidden fields. Remember that HttpWebRequest requires a
CookieContainer instance, otherwise the corresponding HttpWebResponse
will not contain any cookies.

Cheers,
 

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

Top