我是QTP和VBScript的新手,我正在尝试将文本文件内容作为响应(示例网址:http://x.x.x.x/dir/MIS/test_667/logfile.667.txt)。以下代码在WindowsXP上按要求工作,但在Windows7 / Windows2008R2上获取'Empty'ResponseText(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