我正在尝试使用RestBuilder
执行以下操作curl -X POST --header "Content-Type: application/xml;charset=UTF-8" --data "</xml_goes_here>" http://www.example.com/api/ -u username:password
我尝试了以下内容:
def rest = new RestBuilder()
def url = 'http://www.example.com/api/?username=username&password=password'
def resp = rest.post(url) {
contentType("text/xml")
body(xmlMessage)
}
def rest = new RestBuilder()
def url = 'http://username:password@www.example.com/api/'
def resp = rest.post(url) {
contentType("text/xml")
body(xmlMessage)
}
def rest = new RestBuilder()
def url = 'http://www.example.com/api/'
def resp = rest.post(url) {
contentType("text/xml")
setProperty("username","username")
setProperty("password","password")
body(xmlMessage)
}
有人管理过吗?
答案 0 :(得分:4)
尝试:
def resp = new RestBuilder().post(url) {
auth username, password
// the rest
}