0

我希望异步 HTTP 回调在 C# 中使用 MSXML2 API 工作。我通过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!

我尝试了 Action()、匿名代表、匿名类型,但没有任何效果!可悲的是,在互联网上存在这个VB.NET 模块驱动的解决方案,但我不确定如何在 C# 中完成。

任何帮助将不胜感激!

4

2 回答 2

1

WinForms应用程序中使用 aWebRequest代替。它基本上以相同的方式工作。

于 2012-05-23T07:55:51.997 回答
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
        }
    }
于 2012-05-23T08:13:11.377 回答