1

QTP と VBScript は初めてで、テキスト ファイルの内容を応答として取得しようとしています (サンプル URL : http://xxxx/dir/MIS/test_667/logfile.667.txt )。以下のコードは、WindowsXP では必要に応じて機能していますが、Windows7/Windows2008R2 では「空」の ResponseText( sIMPResponse = objWinHTTP.ResponseText) を取得しています。

http://www.zytrax.com/tech/web/msie-history.htmlでさまざまな User-Agent 文字列を試してみましたが、うまくいきませんでした。

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