问题
每次我们尝试从 Web 服务器读取文件 (ASP) 的内容时,Msxml2.ServerXMLHTTP 都会不断返回 401 - 未经授权的错误。
源服务器运行 IIS6,使用 NTLM 集成登录。
此过程以前已成功使用,但仅用于从外部网站提取 XML 文件,而不是从内部网站提取 XML 文件。
运行脚本的服务器注册表中的代理设置也已更新,以绕过相关网站,但无济于事。
VBScript 中标识的所有路径都经过检查和测试,并且是正确的。
运行脚本的用户对脚本中引用的所有位置具有正确的读/写权限。
需要解决方案
确定 HTTP 401 Unauthorized 消息的原因,以便脚本按预期工作。
描述
我们的组织运营着一个内部网,其中的内容被复制到我们每个远程站点的服务器上。这确保了这些站点即使在失去连接的情况下也能继续快速访问重要信息、文档和数据。
我们正在改进表格的列表和管理(那些必须为特定任务填写的讨厌的纸)。这涉及建立我们所有表格的数据库。
但是,由于该组织还不够聪明,无法在每个站点上投资 MSSQL Server 实例,因此无法选择复制数据库并从本地 SQL Server 访问它。
为了解决这个问题,我构建了一系列显示所需数据的视图(ASP 页面)。然后我打算通过 VBScript 使用 Msxml2.ServerXMLHTTP,这样我就可以读取结果页面并将输出保存到服务器上的静态文件中。
从那里,现有的复制过程可以将这些文件流式传输到站点 - 用户不知道他们正在查看恰好从数据库输出生成的静态页面。
代码
' Forms - Static Page Generator
' Implimented 2011-02-15 by Michael Harris
' Purpose: To download the contents of a page, and save that page to a static file.
' Target category: 1 (Contracts)
' Target Page:
' http://sharename.fpc.wa.gov.au/corporate/forms/generator/index.asp
' Target path: \\servername\sharename\corporate\forms\index.asp
' Resulting URL: http://sharename.fpc.wa.gov.au/corporate/forms/index.asp
' Remove read only
' Remove read only flag on file if present to allow editing
' If file has been set to read only by automated process, turn off read only
Const READ_ONLY = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("\\server\sharename\corporate\forms\index.asp")
If objFile.Attributes AND READ_ONLY Then
objFile.Attributes = objFile.Attributes XOR READ_ONLY
End If
Dim webObj, strURL
Set webObj = CreateObject("Msxml2.ServerXMLHTTP")
strURL = "http://sharename.fpc.wa.gov.au/corporate/forms/generator/index.asp"
webObj.Open "GET", strURL
webObj.send
If webObj.Status=200 Then
Set objFso = CreateObject("Scripting.FileSystemObject")
Set txtFile = objFso.OpenTextFile("file:\\servername.fpc.wa.gov.au\sharename\corporate\forms\index.asp", 2, True)
txtFile.WriteLine webObj.responseText
txtFile.close
ElseIf webObj.Status >= 400 And webObj.Status <= 599 Then
MsgBox "Error Occurred : " & webObj.Status & " - " & webObj.statusText
Else
MsgBox webObj.ResponseText
End If