0

I wrote a script that downloads file from web using file URL. I have an ActiveXObject of following type.

var objHTTP = new ActiveXObject("MSXML2.XMLHTTP");  
objHTTP.open("GET", strFileURL, false);

It works perfect for small size file says, file size less than 100MB. But when I try to download file with size greater than 100MB my script hanged. Then I tried,

objHTTP.open("GET", strFileURL, true);

but in this case we have to implement a callback function. I don't know how to implement callback and then use it. Can somebody help me. I am using TestComplete 7. Script that I wrote;

var objHTTP = new ActiveXObject("MSXML2.XMLHTTP"); 
  objHTTP.open("GET", strFileURL, true); 
  objHTTP.onreadystatechange = Callback; 
  objHTTP.send();  
  while((objHTTP.readyState != 4) && (objHTTP.readyState != 'complete'))  
  {   
    Delay(100); 
  }  
  if(200 != objHTTP.Status)  
  {  
    Log.Error("The " + strFileURL + " file was not found." + " The returned status is " + objHTTP.Status); 
    return;  
  }  

I don't know how to implement Callback function. Can somebody provide me implementation?

Thanks

4

1 回答 1

0

可能,挂起是 while 循环等待 readyState 属性的特定值的结果。如果该属性从未获得预期值之一,则脚本将永远工作。

我认为 MSXML2.XMLHTTP 对象无法加载大文件,并且永远不会将 readyState 设置为脚本期望的值之一。要了解到底发生了什么,我会检查该属性在很长一段时间后的值,这足以让文件加载或尝试失败(比如 2 小时)。如果知道下载失败时readyState属性有什么值,可以在脚本中处理,避免挂起。

这就是悬挂本身。现在关于文件下载问题的原因。我找到了一个页面来说明问题并建议设置更高的超时时间 - 看看: http ://edgylogic.com/blog/downloading-large-files-vbscript/

该示例在 VBScript 中,但使用 JScript 实现相同的方法应该很容易。请注意,该示例使用不同的 COM 对象 - ServerXMLHTTP。你可以在这里阅读它(包括与 XMLHTTP 的差异):http: //msdn.microsoft.com/en-us/library/ms762278 (v=VS.85).aspx

我希望这有帮助。

于 2011-05-08T15:40:54.230 回答