使用vbscript为rest api设置抢占式身份验证

时间:2018-08-29 01:30:02

标签: vbscript hp-uft

我正在使用以下代码通过UFT(VBScript)测试Rest API。

url ="http://*********"
username = "test"
Pwd = "pwd"
inputfilepath  = "C:\TApps\Message.txt"
Set fso = createobject("Scripting.FileSystemObject")
Set fl = fso.OpenTextFile(inputfilepath)
strMsg = fl.readall
Set f1 = Nothing
fl.Close
Set fso = Nothing

Set restReq = CreateObject("Microsoft.XMLHTTP")
restReq.Open "POST", url, False,username,Pwd
restReq.setRequestHeader "Content-Type","application/json"
'restReq.SetRequestHeader "Authentication", "preemptive"
''restReq.setRequestHeader "PreemptiveAuthentiction",true
 restReq.setRequestHeader "Accept","application/json"
 restReq.Send strMsg
msgbox restReq.responsetext

我收到错误消息,如responseText所示

[{"error-code":"1","error_msg":"error when reading the key:null}]

json字符串没有问题,因为手动得到正确的响应。经过分析,我知道对于我的请求,“抢先身份验证”应为true。通过使用“ SetRequestHeader”进行设置进行了尝试,但是没有运气。

0 个答案:

没有答案