HttpWebRequest.BeginGetResponse() does not return the second time
- by evilfred
Hi,
I make one HttpWebRequest and call GetResponse() on it to get a synchronous response.
Then after processing that response, I make a new HttpWebRequest and call BeginGetResponse() on it. Since BeginGetResponse() is an asynchronous call I expect it to return right away, but it doesn't! Why not?
Here is some stripped down sample code:
HttpWebRequest request = RequestFactory.MakeSessionCreationRequest();
try
{
// Get the response from the server.
using (WebResponse response = request.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
; // Get the response.
}
}
; // Process the response.
}
catch (WebException e)
{
Logger("Caught WebException when attempting to connect: " + e);
return;
}
// Make the second, asynchronous request.
HttpWebRequest msgRequest = RequestFactory.MakeMessageRequest();
IAsyncResult result = msgRequest.BeginGetResponse(
new AsyncCallback(HandleResponse),
msgRequest);
// PROBLEM: This line is never reached!!!
Logger("Message send started");