vbs中带有REST API令牌的POST URL,无需密码

时间:2019-09-27 06:45:53

标签: rest jenkins vbscript

我正在使用以下方法在本地Jenkins上启动构建作业:

curl -X POST "http://UID:TOKEN@server:port/job/DevGate/build?delay=0sec&json=%7B%22parameter%22%3A+%7B%22name%22%3A+%22DEVGATE_PACKAGELIST%22%2C+%22value%22%3A+%2212345678%3A9%22%7D%2C+%22statusCode%22%3A+%22303%22%2C+%22redirectTo%22%3A+%22.%22%7D&Submit=Build"

翻译成

curl -X POST "http://UID:TOKEN@server:port/job/DevGate/build?delay=0sec&json={"parameter": {"name": "DEVGATE_PACKAGELIST", "value": "12345678:9"}, "statusCode": "303", "redirectTo": "."}&Submit=Build"

UID是用户ID。 TOKEN是Jenkins / REST API给出的API令牌。而且有效。现在,此命令在VBScript内部启动,该VBScript主要收集用于创建上述URL的数据。不需要密码,我想保持这种方式。问题:我想避免使用curl,而只使用本机VBScript功能。

到目前为止,我已经尝试过:

Dim http: Set http = CreateObject("Microsoft.XMLHTTP")
Dim url: url = "http://server:port/job/DevGate/build"
Dim data: data = "delay=0sec&json=%7B%22parameter%22:+%7B%22name%22:+%22DEVGATE_PACKAGELIST%22,+%22value%22:+%22" + the rest of data
'string2try = Base64EncodeString("UID:TOKEN")
'string2try = Base64EncodeString("UID:PASSWORD")
With http
  .Open "POST", url, False
   Call .SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
   Call .SetRequestHeader("oAuth", token)
  .Send data
  'Call .SetRequestHeader("X-Api-Key", token)
  'Call .SetRequestHeader("Authorization", "Bearer " & token)
  'Call .SetRequestHeader("X-Auth-Token", token or string2try)
  'Call .SetRequestHeader("X-Parse-REST-API-Key", token)
End With

该代码的每个排列都无法通过身份验证。如何在不使用curl的情况下在VBScript中正确传递我的令牌+ uid

0 个答案:

没有答案