【问题标题】:Asynchronous MSXML2 XMLHTTP Request in code behind后面代码中的异步 MSXML2 XMLHTTP 请求
【发布时间】:2012-05-29 17:58:04
【问题描述】:

我希望异步 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 Module driven solution 存在,但我不确定如何在 C# 中完成。

任何帮助将不胜感激!

【问题讨论】:

    标签: c# .net xmlhttprequest msxml4


    【解决方案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
            }
        }
    

    【讨论】:

      【解决方案2】:

      WinForms 应用程序中,请改用WebRequest。它的工作原理基本相同。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-22
        • 1970-01-01
        相关资源
        最近更新 更多