0

I want asynchronous HTTP call back to work in C# with MSXML2 APIs. I am calling this via a winform.

        x = new MSXML2.XMLHTTPClass();
        x.open("POST", "http://localhost/MyHandler.ashx", true, null, null);
        x.send("<test/>");
        x.onreadystatechange = ???? //// What to specify here in C#?
        var response = x.responseText; //// Works great synchronous!

I tried Action(), anonymous delegates, anonymous types but nothing works! Sadly on the internet this VB.NET Module driven solution exists but I am not sure how this can be done in C#.

Any help would be greatly appreciated!

WPF-it
  • 19,625
  • 8
  • 55
  • 71

2 Answers2

1

In a WinForms application use a WebRequest instead. It basically works the same way.

Ben
  • 34,935
  • 6
  • 74
  • 113
1
try {
            System.Net.HttpWebRequest oHTTPRequest = System.Net.HttpWebRequest.Create("URL of Request") as System.Net.HttpWebRequest;
            System.Net.HttpWebResponse oHTTPResponse = oHTTPRequest.GetResponse as System.Net.HttpWebResponse;
            System.IO.StreamReader sr = new System.IO.StreamReader(oHTTPResponse.GetResponseStream);
            string respString = System.Web.HttpUtility.HtmlDecode(sr.ReadToEnd());
        } 
        catch (Exception oEX) 
        {
            //Log an Error
        }
    }
Laird Streak
  • 397
  • 5
  • 8