1

我是 QTP 和 VBScript 的新手,我正在尝试获取文本文件内容作为响应(示例 URL:http://xxxx/dir/MIS/test_667/logfile.667.txt)。下面的代码在 WindowsXP 上按要求工作,但在 Windows7/Windows2008R2 上得到“空”响应文本(sIMPResponse = objWinHTTP.ResponseText)。

我尝试了不同的用户代理字符串@ http://www.zytrax.com/tech/web/msie-history.html,但没有运气。

任何人都可以协助解决获取 WinHTTP.ResponseText 的 .txt 文件内容的解决方案。

在此先感谢您的帮助。

代码片段:

    Dim sResponse, sIMPResponse

    Function PortalUrlExists(ByVal sUrl)
    On Error Resume Next
    UrlExists = False
    Dim objWinHTTP, nStatus
    'Create a WinHTTP Request using the link's URL
    Set objWinHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
    If Err.Number <> 0 Then
     Exit Function
     End If
     objWinHTTP.Open "GET", sUrl, False
     objWinHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"
     'Send the Request to the Server and capture the response
     objWinHTTP.SetTimeouts 180000, 180000, 180000, 180000
     objWinHTTP.Send 
     If Err.Number <> 0 Then
      Set objWinHTTP = Nothing
      Exit Function
     End If
     nStatus = objWinHTTP.Status
     If nStatus = 200 Then
       UrlExists = True
      If InStr(1, sUrl, ".txt", vbTextCompare) > 0 Then
       sIMPResponse = objWinHTTP.ResponseText  ' ***** This is getting "Empty", where as it has to get the text file content from the URL ****
      Else sResponse = objWinHTTP.ResponseText
      End If
     End If
     Set objWinHTTP = Nothing
    End Function
4

0 回答 0