1

I send POST and GET WebRequest that should support longer periods of internet being down. The idea is to queue the failed (timedout) webrequest and to try to resend them periodically until the internet is up again and all queued WebRequests are sent.

However, I seems that I cannot just reuse the old WebRequest. Do I need to set it up again?

IAsyncResult result = request.BeginGetResponse (o => {
        callCallback (o);
}, state);

When request is just setup using:

var request = HttpWebRequest.Create (String.Format (@"{0}/{1}", baseServiceUrl, path)); 
request.Method = "GET";
request.ContentType = "application/xml; charset=UTF-8";
request.Headers.Add ("Authority", account.Session);
return request;

it works fine. But after a timeout (and request.Abort ();) and calling BeginGetResponse() on the same webrequest just freezes.

Sunkas
  • 9,542
  • 6
  • 62
  • 102
  • 1
    Possible duplicate? - http://stackoverflow.com/questions/2179626/reuse-a-httpwebrequest And another - http://stackoverflow.com/questions/4933450/can-i-reuse-httpwebrequest-without-disconnecting-from-the-server – Snixtor Mar 07 '13 at 10:25
  • That question does not call `Abort()` to request. – Sunkas Mar 07 '13 at 10:30

1 Answers1

1

You cannot call BeginGetResponse() multiple times on the same HttpWebRequest. I'm not sure whether that's support on .NET, but it's not possible with Mono's implementation (and not something that'd be easy to change).

See also Can I reuse HttpWebRequest without disconnecting from the server? - the underlying network connection will be reused.

Community
  • 1
  • 1
Martin Baulig
  • 3,010
  • 1
  • 17
  • 22
  • 1
    Thanks. I solved it by creating a wrapper around WebRequest that stores the data that is used to setup the request. This to be able to recreate it. – Sunkas Mar 08 '13 at 08:39
  • 1
    I love these answers. I found out how to do it but I am not gonna share it with others. – Gregg Dec 05 '16 at 02:08