WebRequest question

  • Thread starter Thread starter J M
  • Start date Start date
J

J M

How do I make one WebRequest with following:

WebRequest
Send data
Receive response
process
Send data II
Receive response II
close connection

If response is in timeout keep trying 5 times and quit.

TIA!
 
J M,

Is there any particular reason why you want to keep the connection open?
The only way that this will work is if the server is supporting HTTP 1.1.
If it is not, then storing the connection is pointless. Also, you won't be
saving any state information based on the connection (at least you shouldn't
be).

If you want to keep the connection open, then set the KeepAlive property
to true. However, if not connecting to a 1.1 server, this would be
pointless, and the header will not be sent.

Hope this helps.
 
J said:
How do I make one WebRequest with following:

WebRequest
Send data
Receive response
process
Send data II
Receive response II
close connection

WebRequest's API more or less abstracts from its low level socket-based
connection management (pretty much the same way HTTP abstracts from TCP).
Just because you're using two WebRequest instances doesn't mean you're using
two different TCP streams. If you're interested in such details, check out
System.Net.ServicePoint and System.Net.ServicePointManager.

Just make sure to use HTTP 1.1 persisten connections (default for
HttpWebRequest anyway), as Nicolas pointed out.

Cheers,
 
No, there is no reason however I am sending http web request to multiple
(hardware embeded) web servers with limited features. Some servers do not
close the connection after first web-request and web response complets (with
webresponse.close() command) and I have to keep retrying until (default time
out 90 seconds for connection) expires for second web request to be started.
The same back to back web requests works fine on some http servers (hardware
embeded). So I am trying common sloution acceptable for both behaviours.
The time out of 90 seconds is kind of not accepatble in my environment since
my code is making several request to several http servers 24x7. Fortunetly
the code works fine except this nagging issue.

I am closing the web response with webresponse.close() for both web
requests however seeing different behaviours in some remote http severs
(hardware embeded).

Any suggestions? TIA!


Nicholas Paldino said:
J M,

Is there any particular reason why you want to keep the connection
open? The only way that this will work is if the server is supporting HTTP
1.1. If it is not, then storing the connection is pointless. Also, you
won't be saving any state information based on the connection (at least
you shouldn't be).

If you want to keep the connection open, then set the KeepAlive
property to true. However, if not connecting to a 1.1 server, this would
be pointless, and the header will not be sent.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

J M said:
How do I make one WebRequest with following:

WebRequest
Send data
Receive response
process
Send data II
Receive response II
close connection

If response is in timeout keep trying 5 times and quit.

TIA!
 
Back
Top