0
XML REST 웹 서비스에서 GET 및 PUT 호출을 시도하고 있습니다.HttpBuilder를 사용하여 XmlSlurper를 REST로 다시 푸는 방법
나는 이런 식으로 수행
@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!
지금 내가 변경하고 난 XML을 전송하지 않는 PUT 요청 HTTPBuilder을 할 때
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)
을 저장하는거야. 그것은 profile.toString()으로 만들어진 문자열을 보낸다.
그것은 내가 기대하는 것이 아닙니다. PUT 요청에서 이전에 얻은 XmlSlurper 개체를 보내는 방법은 무엇입니까?
감사합니다.