【发布时间】:2011-02-15 05:48:08
【问题描述】:
问题
Msxml2.ServerXMLHTTP 每次尝试从 Web 服务器读取文件 (ASP) 的内容时都会返回 401 - 未经授权的错误。
源服务器正在运行 IIS6,使用 NTLM 集成登录。
此过程之前已成功使用,但仅用于从外部网站提取 XML 文件,而不是从内部网站提取 XML 文件。
运行脚本的服务器注册表中的代理设置也已更新以绕过相关网站,但无济于事。
VBScript 中标识的所有路径都经过检查和测试,并且是正确的。
运行脚本的用户对脚本中引用的所有位置具有正确的读/写权限。
需要解决方案
确定 HTTP 401 Unauthorized 消息的原因,以便脚本按预期工作。
说明
我们的组织运营着一个 Intranet,其中的内容被复制到我们每个远程站点的服务器上。这可确保这些站点即使在断开连接的情况下也能继续快速访问重要信息、文档和数据。
我们正在改进表单的列表和管理(对于特定任务必须填写的那些讨厌的纸张)。这涉及建立我们所有表单的数据库。
但是,由于组织还不够聪明,无法在每个站点投资 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
【问题讨论】:
-
您是说“源服务器正在运行 IIS6,使用 NTLM 集成登录”。这并不意味着 ServerXMLHTTP 会自动从您的请求发出的服务器应用“正确的凭据”。
标签: asp-classic vbscript msxml serverxmlhttp