问题
每次我们尝试从 Web 服务器读取文件 (ASP) 的内容时,Msxml2.ServerXMLHTTP 都会返回 401 - 未经授权的错误。
源服务器正在运行 IIS6,使用 NTLM 集成登录。
此过程以前已成功使用,但仅限于从外部网站提取 XML 文件,而不是内部网站。
运行脚本的服务器注册表中的代理设置也已更新,以绕过相关网站,但无济于事。
VBScript 中标识的所有路径都经过检查和测试,都是正确的。
运行脚本的用户对脚本中引用的所有位置具有正确的读/写权限。
需要解决方案
确定 HTTP 401 Unauthorized 消息的原因,以便脚本按预期工作。
描述
我们的组织运营一个内部网,其中的内容被复制到我们每个远程站点的服务器上。这确保了这些站点即使在失去连接的情况下也能持续快速访问重要信息、文档和数据。
我们正在改进表单(那些必须填写特定任务的烦人的纸张)的列表和管理。这涉及建立我们所有表格的数据库。
但是,由于组织还不够聪明,无法在每个站点投资 MSSQL Server 实例,因此无法选择复制数据库并从本地 SQL Server 访问数据库。
为了解决这个问题,我构建了一系列显示所需数据的 View (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
最佳答案
更换线路:
webObj.Open "GET", strURL
与:
webObj.Open "GET", strURL, False, "username", "password"
在大多数情况下,401 Unauthorized 表示您尚未提供凭据。此外,您还应该指定 False 来指示您不需要异步模式。
关于asp-classic - 尝试将 ASP 页面下载到文件时出现 401 未经授权的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5000311/