当我用HttpBuilder发布Soap请求时,我得到一个例外。 我的代码:
def reqxml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
" <soapenv:Header/>\n" +
" <soapenv:Body>\n" +
" <web:GetWeather xmlns:web=\"http://www.webserviceX.NET\">\n" +
" <web:CityName>Berlin</web:CityName>\n" +
" <web:CountryName>Germany</web:CountryName>\n" +
" </web:GetWeather>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>"
def http = new HTTPBuilder("http://www.webservicex.com/globalweather.asmx?WSDL")
http.request(Method.POST, ContentType.XML) {
body = reqxml
response.success = { resp, xml ->
println (xml)
}
response.failure = {resp, xml ->
println "Error"
}
}
此代码抛出SAXParseException,并在prolog中不允许使用Content。 发生在http.request方法。