我希望异步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#中做到这一点。
非常感谢任何帮助!
答案 0 :(得分:1)
在WinForms
应用中,请改用WebRequest
。它的工作原理基本相同。
答案 1 :(得分: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
}
}