0

我正在从我的服务器读取文本文件,如下所示,但我想知道如何从不同的服务器读取 txt 文件?我需要做什么才能让它工作?

Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("files.txt"), 1)

do while f.AtEndOfStream = false
Response.Write(f.ReadLine)
Response.Write("<br>")
loop

f.Close
Set f=Nothing
Set fs=Nothing

所以这是正常工作,但我想将 files.txt 更改为http://www.somedomain.com/files.txt

任何输入表示赞赏,谢谢!

4

2 回答 2

2

Claes,试试这个,让我们知道。

<% Option Explicit %>
<%
Const REMOTE_FILE_URL="http://www.somedomain.com/files.txt"

Call ShowRemoteFile

Sub ShowRemoteFile
    Dim objXML, strContents, arrLines
    Dim x
    Set objXML=Server.CreateObject("Microsoft.XMLHTTP")

    'read text file...
    objXML.Open "GET", REMOTE_FILE_URL, False
    objXML.Send
    strContents=objXML.ResponseText
    Set objXML=Nothing

    'split into lines and read line by line...
    arrLines=Split(strContents, VBCrLf)
    For x=0 To UBound(arrLines)
        Response.Write(arrLines(x)&"<br />")
    Next
End Sub
%>
于 2013-04-29T09:30:28.937 回答
0

Use this function to fetch the text data (taken from here):

Function GetTextFromUrl(url)

  Dim oXMLHTTP
  Dim strStatusTest

  Set oXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.3.0")

  oXMLHTTP.Open "GET", url, False
  oXMLHTTP.Send

  If oXMLHTTP.Status = 200 Then

    GetTextFromUrl = oXMLHTTP.responseText

  End If

End Function

Dim sResult : sResult = GetTextFromUrl("http://www.somedomain.com/files.txt")
于 2013-04-29T09:04:47.293 回答