我正在尝试使用具有3个参数(用户,通过,领域)的POST请求获取身份验证票证,以访问Proxmox API Server进行解析以进行进一步的查询。
当我用Groovy脚本为Jenkins作业中的参数编写代码时,在错误方面我没有得到太多帮助。我已经尝试过关于失眠的POST请求,并且没有问题。
我对GroovyScript还是很陌生,任何朝着正确方向的指针都值得赞赏。
def url = new URL("https://$HOST/api2/json/access/ticket")
def connection = url.openConnection()
connection.setDoOutput(true)
connection.setRequestMethod("POST")
connection.setRequestProperty("Content-Type", "application/json")
connection.setRequestProperty('Username', '$USER')
connection.setRequestProperty('Password', '$PASS')
connection.setRequestProperty('Realm', '$REALM')
def requestCode = connection.getResponseCode
答案 0 :(得分:0)
不需要connection.setRequestProperty('Realm', '$REALM')
,使用Username@realm
试试这个,写信给API:
def url = new URL("https://$HOST/api2/json/access/ticket")
def connection = url.openConnection()
connection.setDoOutput(true)
connection.setRequestMethod("POST")
connection.setRequestProperty("Content-Type", "application/json")
connection.setRequestProperty('Password', '$PASS')
connection.setRequestProperty('Username', '$USER' + '@' + '$REALM')
def requestCode = connection.getResponseCode