1

I'm new to QTP and VBScript and I'm trying to get the text file content as a response(sample URL : http://x.x.x.x/dir/MIS/test_667/logfile.667.txt). The below code is working as required on WindowsXP, but getting 'Empty' ResponseText( sIMPResponse = objWinHTTP.ResponseText) on Windows7/Windows2008R2.

I tried with different User-Agent strings @ http://www.zytrax.com/tech/web/msie-history.html , but no luck.

Can anyone please assist on the solution to get the .txt file content for WinHTTP.ResponseText.

Thanks in advance for your help.

CodeSnippet:

    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
Veera
  • 11
  • 1
  • 2
  • Remove the line `On Error Resume Next` and try again. – Ansgar Wiechers Jan 20 '13 at 21:26
  • Thanks for your reply... Up on removing 'On Error Resume Next' getting data in unexpected format. Part of Respose: 䕒佃䑒䄠瑣潩䱮獩䙴汩孥崱਍ൻ. Please suggest how to resolve this. – Veera Jan 21 '13 at 02:23
  • we have used "Microsoft.XmlHttp" instead of "WinHttp.WinHttpRequest.5.1" object, and is working as required – Veera Jan 23 '13 at 14:45

0 Answers0