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#.

2 Answers 2

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
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.