最近发现Microsoft.XMLHTTP很好用。
想在Delphi中实现一个桌面的客户端应用,使用MS XML4.0中的XMLHTTP4.0来实现xml的http通讯。
可惜,在Javascript中的异步模式居然在Delphi中实现不了。。唉,郁闷啊
MSDN中的说明:
Note that onreadystatechange is designed for use in scripting environments
and is not readily accessible in Microsoft Visual Basic or C++.
看一个JavaScript中的实例,真是很flexbility
var gThreadRequest=null;
var gRequestXML='<xml>...';
function AsyncDataExchg()
{
if (gThreadRequest == null)
AsyncRequest ("http://...", gRequestXML);
}
function AsyncRequest (url, xmlstr)
{
gThreadRequest = new ActiveXObject("Microsoft.XMLHTTP");
gThreadRequest.Open("POST", url, true);
gThreadRequest.onreadystatechange = handleChange;
gThreadRequest.Send (xmlstr);
}
function handleChange ()
{
if (gThreadRequest!= null && gThreadRequest.readyState == 4)
var xmlret = gThreadRequest.responseText;
// do something...
gThreadRequest = null;
}
}