I have trouble following the examples to get the callback.
I have the following code:
private void startWebRequest(object sender, EventArgs e)
{
Uri url = new Uri("http://localhost.com/dummyGet");
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.BeginGetResponse(new AsyncCallback(ReadWebRequestCallback), request);
}
private void ReadWebRequestCallback(IAsyncResult callbackResult)
{
Console.WriteLine("Don not get here");
try
{
var req = (HttpWebRequest)callbackResult.AsyncState;
using (var response = req.EndGetResponse(callbackResult))
{
Console.WriteLine("Code");
}
}
catch
{ }
}
I have been bangin my head against this all day, I can see the get request in my browser, or with client in fiddler/wireshark. But the code (ReadWebRequestCallback) does not get called.
Edit: Also note that if I use WebClient and DownloadStringAsync it works, but i need other HTTP status codes than 404 and 200.:
_client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadStringCompleted);
_client.DownloadStringAsync(_concurrentCheckUrl);
}
private void DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{// Works, gets here}