如何使用httpbuilder在groovy中正确地形成post请求
我知道以前有人问过这个问题,在过去的几天里我一直在寻找如何在groovy中正确地做到这一点,但我没有任何运气。我可以用邮递员做得很好如何使用httpbuilder在groovy中正确地形成post请求,groovy,Groovy,我知道以前有人问过这个问题,在过去的几天里我一直在寻找如何在groovy中正确地做到这一点,但我没有任何运气。我可以用邮递员做得很好 import groovyx.net.http.HTTPBuilder import static groovyx.net.http.ContentType.* import groovyx.net.http.ContentType import static groovyx.net.http.Method.* import groovy.json.JsonSlu
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import static groovyx.net.http.Method.*
import groovy.json.JsonSlurper
import net.sf.json.groovy.JsonSlurper
def remote = new HTTPBuilder("https://jira.company.com/rest/com-spartez-ephor/1.0")
remote.request(POST) { req ->
uri.path = "/workflow/jira/issue/16600/link/TS-6825"
headers.'Content-Type' = 'application/json'
headers.'Authorization' =
"Basic ${"uuuu:pppp".bytes.encodeBase64().toString()}"
response.success = { resp, json ->
json ?: [:]
}
}
如果您有任何帮助,我们将不胜感激。使用:
您的代码可能如下所示:
import static groovyx.net.http.HttpBuilder.configure
import static groovyx.net.http.ContentTypes.JSON
def remote = configure {
request.uri = 'https://jira.company.com/rest/com-spartez-ephor/1.0'
request.contentType = JSON[ 0 ]
request.auth.basic 'uuuu', 'pppp'
}
remote.post { req ->
request.uri.path = "/workflow/jira/issue/16600/link/TS-6825"
response.success { resp, json ->
println json
}
response.exception { t ->
println t
}
}
import static groovyx.net.http.HttpBuilder.configure
import static groovyx.net.http.ContentTypes.JSON
def remote = configure {
request.uri = 'https://jira.company.com/rest/com-spartez-ephor/1.0'
request.contentType = JSON[ 0 ]
request.auth.basic 'uuuu', 'pppp'
}
remote.post { req ->
request.uri.path = "/workflow/jira/issue/16600/link/TS-6825"
response.success { resp, json ->
println json
}
response.exception { t ->
println t
}
}