import groovy.json.JsonOutput
void api(){
def data = [jobId : "11111111111111", data : 5,status: 2]
def url = new URL("http://localhost:8888/jenkinsApi/postData")
def conn = url.openConnection()
conn.setRequestMethod("POST")
conn.setRequestProperty("Content-Type", "application/json")
conn.doOutput = true
def writer = new OutputStreamWriter(conn.outputStream)
println JsonOutput.toJson(data)
writer.write(JsonOutput.toJson(data))
writer.flush()
writer.close()
conn.connect()
def code = conn.getResponseCode()
println conn.content.text
println code
}
转载于:https://www.cnblogs.com/zhizhao/p/11244243.html