vbscript xmlhttp请求身份验证。访问被拒绝

时间:2014-04-25 22:22:47

标签: xml authentication vbscript xmlhttprequest vlc

我正在尝试从VLC Web界面中获取xmldocument。在过去,我的脚本按预期工作,但是最新版本的VLC引入了访问Web界面的身份验证,似乎无法禁用它(或更改用户名)。

            On Error Resume Next
            Set xmlDoc = CreateObject("Msxml2.XMLHTTP.6.0")

            xmlDoc.Open "GET","http://localhost:8080/requests/status.xml", false, "", "password"
            xmlDoc.send()

我知道我提供的用户/通行证是正确的,因为我可以通过浏览器访问该文档。有什么想法吗?

由于

2 个答案:

答案 0 :(得分:1)

问题是我需要使用base64格式的密码设置请求标头

xmlDoc.Open "GET","http://localhost:8080/requests/status.xml", false, "", "password"
xmlDoc.send()

应该是

Dim base64pw
base64pw = "OnBhc3N3b3Jk"
xmlDoc.Open "GET","http://localhost:8080/requests/status.xml", false, "", "password"
xmlDoc.setRequestHeader "Authorization", "Basic "& base64pw
xmlDoc.send()

答案 1 :(得分:0)

使用xmlhttp尝试这种方式。编辑网址等。如果它似乎工作注释if / end if转储信息,即使看起来工作。它是vbscript但vbscript在vb6中工作。

 On Error Resume Next
 Set File = WScript.CreateObject("Microsoft.XMLHTTP")
 File.Open "GET", "http://www.microsoft.com/en-au/default.aspx", False
 'This is IE 8 headers
 File.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)"
 File.Send
 If err.number <> 0 then 
    line =""
    Line  = Line &  vbcrlf & "" 
    Line  = Line &  vbcrlf & "Error getting file" 
    Line  = Line &  vbcrlf & "==================" 
    Line  = Line &  vbcrlf & "" 
    Line  = Line &  vbcrlf & "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description 
    Line  = Line &  vbcrlf & "Source " & err.source 
    Line  = Line &  vbcrlf & "" 
    Line  = Line &  vbcrlf & "HTTP Error " & File.Status & " " & File.StatusText
    Line  = Line &  vbcrlf &  File.getAllResponseHeaders
    wscript.echo Line
    Err.clear
    wscript.quit
 End If

On Error Goto 0

 Set BS = CreateObject("ADODB.Stream")
 BS.type = 1
 BS.open
 BS.Write File.ResponseBody
 BS.SaveToFile "c:\users\test.txt", 2

同时查看这些其他对象是否有效。

C:\Users>reg query hkcr /f xmlhttp

HKEY_CLASSES_ROOT\Microsoft.XMLHTTP
HKEY_CLASSES_ROOT\Microsoft.XMLHTTP.1.0
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.3.0
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.4.0
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.5.0
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.6.0
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP.3.0
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP.4.0
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP.5.0
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP.6.0
End of search: 12 match(es) found.