HttpWebRequest keepalive

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cliff Harris

    #1

    HttpWebRequest keepalive

    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


  • Joerg Jooss

    #2
    Re: HttpWebRequest keepalive

    "Cliff Harris" wrote:
    [color=blue]
    > 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?[/color]

    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,
    --
    Joerg Jooss
    joerg.jooss@gmx .net

    Comment

    Working...