Rest 如何使用HttpBuilder恢复XmlSlurper

Rest 如何使用HttpBuilder恢复XmlSlurper,rest,groovy,httpbuilder,xmlslurper,http-put,Rest,Groovy,Httpbuilder,Xmlslurper,Http Put,我正在尝试对XMLRESTWeb服务进行GET和PUT调用 我是这样做的: @Grab('org.codehaus.groovy.modules.http-builder:http-builder:0.7') import groovyx.net.http.HTTPBuilder import static groovyx.net.http.ContentType.* import static groovyx.net.http.Method.* import groovy.xml.XmlUti

我正在尝试对XMLRESTWeb服务进行GET和PUT调用

我是这样做的:

@Grab('org.codehaus.groovy.modules.http-builder:http-builder:0.7')
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import groovy.xml.XmlUtil

def url = "http://localhost:81"
def pathPrefix = "/api/v1"

def http = new HTTPBuilder(url)
def profile = http.request(GET, XML) { req ->
    uri.path = "$pathPrefix/profiles/55"
    response.success = {resp, xml ->
        xml
    }
}

println XmlUtil.serialize(profile) // this is fine!
现在我要更改并保存

profile.name = "New Name"

// this is not fine (i have 400 Bad Request)
// because it sends body not in XML
def savedProfile = http.request(PUT, XML) { req ->
    uri.path = "$pathPrefix/profiles/55"
    body = profile
    response.success = {resp, xml ->
        xml
    }
}

println XmlUtil.serialize(savedProfile)
当我发出PUT请求时,HTTPBuilder不发送XML。它发送由profile.toString组成的字符串

这不是我所期望的。 如何发送我之前在PUT请求中获得的XmlSlurper对象


谢谢。

我想我找到了解决办法。 当我定义body配置值时,我必须编写

body = {
    mkp.yield profile
}