Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp classic 401尝试将ASP页面下载到文件时出现未经授权的错误_Asp Classic_Vbscript_Msxml_Serverxmlhttp - Fatal编程技术网

Asp classic 401尝试将ASP页面下载到文件时出现未经授权的错误

Asp classic 401尝试将ASP页面下载到文件时出现未经授权的错误,asp-classic,vbscript,msxml,serverxmlhttp,Asp Classic,Vbscript,Msxml,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/corpo

问题

' 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
Msxml2.ServerXMLHTTP每次尝试从web服务器读取文件(ASP)内容时都会返回401-未经授权的错误

源服务器正在使用NTLM集成登录运行IIS6

此过程以前已经成功使用过,但仅限于从外部网站(而不是内部网站)提取XML文件

运行脚本的服务器的注册表中的代理设置也已更新,以绕过相关网站,但无效

VBScript中标识的所有路径都已检查和测试,并且都是正确的

运行脚本的用户对脚本中引用的所有位置具有正确的读/写权限

需要解决方案

确定HTTP 401未经授权消息的原因,以便脚本按预期工作

说明

我们的组织运营一个内部网,内容被复制到我们每个远程站点的服务器上。这确保了这些站点能够继续快速访问重要信息、文档和数据,即使在失去连接的情况下也是如此

我们正在改进表格的列表和管理(那些需要填写特定任务的讨厌的纸)。这包括建立一个我们所有表格的数据库

然而,由于该组织还没有足够的智慧在每个站点上投资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
”表单-静态页面生成器
迈克尔·哈里斯于2011年2月15日发布
'目的:下载页面内容,并将该页面保存到静态文件中。
'目标类别:1(合同)
'目标页面:
' http://sharename.fpc.wa.gov.au/corporate/forms/generator/index.asp
'目标路径:\\servername\sharename\corporate\forms\index.asp
'结果URL:http://sharename.fpc.wa.gov.au/corporate/forms/index.asp
'删除只读
'删除文件上的只读标志(如果存在)以允许编辑
'如果自动进程已将文件设置为只读,请关闭只读
常数只读=1
设置objFSO=CreateObject(“Scripting.FileSystemObject”)
设置objFile=objFSO.GetFile(“\\server\sharename\corporate\forms\index.asp”)
如果objFile.Attributes和只读
objFile.Attributes=objFile.Attributes XOR只读
如果结束
Dim webObj,strURL
设置webObj=CreateObject(“Msxml2.ServerXMLHTTP”)
strURL=”http://sharename.fpc.wa.gov.au/corporate/forms/generator/index.asp"
webObj.打开“获取”,strURL
webObj.send
如果webObj.Status=200,则
设置objFso=CreateObject(“Scripting.FileSystemObject”)
设置txtFile=objFso.OpenTextFile(“文件:\\servername.fpc.wa.gov.au\sharename\corporate\forms\index.asp”,2,True)
txtFile.WriteLine webObj.responseText
txtFile.close

ElseIf webObj.Status>=400和webObj.Status我将首先测试您是否可以在运行代码的服务器X上通过普通浏览器访问url(a)。然后我会尝试从另一台PC访问该url。一台从未访问过该url,但与服务器X(B)位于同一网络中

如果B工作,但A不工作,我会怀疑出于某种原因,您的源服务器(即为url提供服务的服务器)出于某种原因阻止了服务器X。检查II6和NTLM的安全设置

如果A和B都不工作,则源服务器通常会出现一些错误(即,它会阻止所有内容,或者NTML不允许您进入)

如果A起作用(B不重要),那么问题一定在代码中的某个地方。那样的话,我建议你。此工具可以实时为您的浏览器和代码提供HTTP请求。然后你可以比较两者。这至少会给你一个关于解决方案的强烈提示(如果不是立即给你的话)。

替换你的线路:

webObj.Open "GET", strURL 
与:


在大多数情况下,401 Unauthorized表示您没有提供凭据。此外,您还应指定False以表示您不需要异步模式。

这听起来像是O.p.通过注册表中正确的代理设置解决了这个问题(解释了为什么代理配置会解决这个问题)。较新版本的ServerXMLHTTP有一个setProxy方法,可以用来在代码中设置必要的代理配置

在上面的O.p.代码中,创建webObj后,以下代码行将正确设置代理:

webObj.setProxy 2, "0.0.0.0:80", "*.fpc.wa.gov.au" 

如果运行代码的用户配置了代理,并且目标URL绕过该代理,则ServerXMLHTTP将传递该用户的凭据。由于您无论如何都要绕过代理,因此可以将其设置为虚拟值
“0.0.0.0:80”
,并确保您的目标url包含在旁路列表中指定的内容
“*.fpc.wa.gov.au”

您的意思是“源服务器正在运行IIS6,使用NTLM集成登录”。这并不意味着ServerXMLHTTP将自动从您的请求源服务器应用“正确的凭据”。我应该提到,我以前尝试过此方法并返回了相同的错误。但是,用于在注册表中正确配置代理配置的MS KB链接(请参阅有关问题的注释)已经完成了使其进行身份验证的技巧。我没有在配置字符串中传递一些开关来让它更好地播放。