1

使用此代码,我能够通过 Digest Authentication 步骤并获得200 ok回报。

这是我的 VBscript 代码:

Option Explicit
Dim restReq, url
Dim jsontext, headerText
Dim fso1 : Set fso1 = CreateObject("Scripting.FileSystemObject")
Dim file1 : Set file1 = fso1.OpenTextFile("\\uspmuusrichm1a\users-h\nguyenhv\2018\PP camera system M.1879\document\Axis decoder\myfile.txt", 2, True)
headerText = "username="&"root"&", "&"realm="&"axis"&", "&"nonce="&"cd0357704fb04263a8203225579087d7"&", "&"uri="&"/axis-cgi/decoder.cgi"&", "&"algorithm="&"MD5"&", "&"response="&"385e2c4ad1be0feb5b8fa453f88e1c1b"&", "&"opaque="&"384b4e29e47341b6a967d94dc6a2c7e2"
Set restReq = CreateObject("MSXML2.serverXMLHTTP")
url = "http://10.67.72.130/axis-cgi/decoder.cgi"
jsontext = "{"&"apiVersion"&": "&"1.0"&" ,"&"context"&": "&"123"&"1.0"&" ,"&"method"&": "&"getCapabilities"&"}"
restReq.open "POST", url, false
restReq.setRequestHeader "Content-Type","application/json"
restReq.setRequestHeader "authorization","Digest " & headerText
restReq.send (jsontext)
file1.WriteLine "Status_Response : " & restReq.Status
file1.WriteLine "HEADER_RESPONSE : " & restReq.getAllResponseHeaders
file1.WriteLine "BODY_RESPONSE : " & restReq.responseText
file1.Close

这是我的解码器响应:

Decoder response
Status_Response : 200
HEADER_RESPONSE : Date: Sat, 31 Jan 1970 16:25:20 GMT
Content-Length: 101
Content-Type: text/html; charset=UTF-8
Server: TornadoServer/4.0.2
Vary: Accept-Encoding
BODY_RESPONSE : {"error": {"message": "None", "code": 202}, "context": "None", "apiVersion": "1.0", "method": "None"}

带有错误代码202,根据解码器手册,错误代码“202”表示

无效的 JSON。

这意味着我在请求中的正文无效。
我对 JSON 文本字符串的翻译是:

{
  "apiVersion": "1.0",
  "context": "123",
  "method": "getViewConfiguration"
}

但这似乎不正确?
最后的障碍,任何帮助表示赞赏!

4

1 回答 1

1

哈利路亚!!

脚本

Option Explicit
Dim restReq, url
Dim jsontext, headerText
Dim fso1 : Set fso1 = CreateObject("Scripting.FileSystemObject")
Dim file1 : Set file1 = fso1.OpenTextFile("\\uspmuusrichm1a\users-h\nguyenhv\2018\PP camera system M.1879\document\Axis decoder\myfile.txt", 2, True)
headerText = "username="&"root"&", "&"realm="&"axis"&", "&"nonce="&"cd0357704fb04263a8203225579087d7"&", "&"uri="&"/axis-cgi/decoder.cgi"&", "&"algorithm="&"MD5"&", "&"response="&"385e2c4ad1be0feb5b8fa453f88e1c1b"&", "&"opaque="&"384b4e29e47341b6a967d94dc6a2c7e2"
Set restReq = CreateObject("MSXML2.serverXMLHTTP")
url = "http://10.67.72.130/axis-cgi/decoder.cgi"
jsontext = "{""apiVersion"": ""1.0"", ""context"": ""123"", ""method"": ""getCapabilities""}"
restReq.open "POST", url, false
restReq.setRequestHeader "Content-Type","application/json"
restReq.setRequestHeader "authorization","Digest " & headerText
restReq.send (jsontext)
file1.WriteLine "Status_Response : " & restReq.Status
file1.WriteLine "HEADER_RESPONSE : " & restReq.getAllResponseHeaders
file1.WriteLine "BODY_RESPONSE : " & restReq.responseText
file1.Close

解码器响应 Status_Response :200 HEADER_RESPONSE :日期:星期六,1970 年 1 月 31 日 18:49:39 GMT 内容长度:215 内容类型:文本/html;charset=UTF-8 服务器:TornadoServer/4.0.2 变化:Accept-Encoding

身体反应:{"data": {"audioCodecs": [], "overlappingPanes": "false", "videoCodecs": ["H.264", "MJPEG", "MPEG4"], "resolution": "1920x1080", "maxStreams": 16}, "context": "123", "apiVersion": "1.0", "method": "getCapabilities"}

于 2018-10-26T16:47:26.183 回答