I'm having problems with examples for getting a 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 hit my head about it all day, I see a request for receipt in my browser or with the client in the script / wirehark. But the code (ReadWebRequestCallback) is not 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) {
Nitro source share