我希望异步HTTP回调能够通过MSXML2 API在C#中工作。我通过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#中做到这一点。
任何帮助都将不胜感激!
发布于 2012-05-23 16:13:11
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-23 15:55:52
在WinForms应用程序中,请改用WebRequest。它的工作方式基本上是一样的。
https://stackoverflow.com/questions/10715662
复制相似问题