def sendPostRequest(url, bodyData) {
def log = Logger.getLogger("LookupManager")
log.setLevel(Level.DEBUG)
def json = new groovy.json.JsonBuilder()
//Step 1: Set base URL, E.g. http://localhost:2990/jira
def baseUrl = "http://localhost:2990/jira";
//Step 2: Set username and password
def userName = "admin"
def password = "admin"
def http = new HTTPBuilder(baseUrl + url)
http.request(POST) {
headers.
'Authorization' = "Basic " + ((userName + ":" + password).bytes.encodeBase64().toString())
headers.
'X-Atlassian-Token' = 'no-check';
requestContentType = URLENC
body = "data=" + bodyData
response.success = {resp, data ->
log.debug("SUCCESS: " + resp.status)
log.debug(data)
return data
}
response.failure = { resp,data ->
log.error("ERROR: " + resp.status)
log.error(data)
return null
}
}
} |