How do you do multiple GETs with HttpWebRequest with keep-alive?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do you use HttpWebRequest for a GET method? I get POST, and I can see
how to do one GET, since the URL is provided in WebRequest.Create, but for
keep-alive, how do you change the URL for each request on the same connection?
 
uncaged said:
How do you use HttpWebRequest for a GET method? I get POST, and I
can see how to do one GET, since the URL is provided in
WebRequest.Create, but for keep-alive, how do you change the URL for
each request on the same connection?

Keep-Alives or persistent connections are not related to a specific
WebRequest instance -- note that the class is called "Request", not
"Connection". Thus, WebRequest objects are always single use instances.
The underlying ServicePoint takes care of TCP connection management.

Cheers,
 
Joerg Jooss said:
Keep-Alives or persistent connections are not related to a specific
WebRequest instance -- note that the class is called "Request", not
"Connection". Thus, WebRequest objects are always single use instances.
The underlying ServicePoint takes care of TCP connection management.

Cheers,

It seems that the ServicePoint class is both a blessing and a curse. My
life, and I'm sure the lives of many future programmers, would be far better
better if only the HttpWebRequest took an optional IPEndPoint for the source
of the request.

Say I have 2 IP addresses on one NIC, and say I have to send requests from
both IP addresses to the same URL, and I need control over the source IP for
the requests. How can I send from IP A, then IP B, then IP A, and have that
3rd request use the same keep-alive connection as the 1st request?
 
uncaged said:
It seems that the ServicePoint class is both a blessing and a curse.
My life, and I'm sure the lives of many future programmers, would be
far better better if only the HttpWebRequest took an optional
IPEndPoint for the source of the request.

Probably yes, but I guess that's a rather rare use case.
Say I have 2 IP addresses on one NIC, and say I have to send requests
from both IP addresses to the same URL, and I need control over the
source IP for the requests. How can I send from IP A, then IP B,
then IP A, and have that 3rd request use the same keep-alive
connection as the 1st request?

That's not covered by HTTP at all. I'd also argue that this contradicts
the basic notion of TCP sockets -- a connection is defined by
- source IP
- source port
- destination IP
- destination port
If any of these four attributes change, you're dealing with a new TCP
connection, thus HTTP persistent connections cannot exist in this
scenario.

Cheers,
 
Back
Top