Groovy:在不使用wsdl的情况下从信封创建和发送SOAP请求(如curl)。
我有大量从数据库中提取的xml字符串,我希望将它们包装成SOAP消息并发送给收件人。我想使用groovy脚本来实现这一点,就像使用curl一样。这意味着我希望避免使用wsdl,而是将现有xml字符串体包装到soap信封中,然后将其发送到收件人的地址和端口。是否有任何方法可以使用wslite或任何其他用于groovy的SOAP api实现此目的?您可以使用Groovy:在不使用wsdl的情况下从信封创建和发送SOAP请求(如curl)。,curl,soap,groovy,wsdl,Curl,Soap,Groovy,Wsdl,我有大量从数据库中提取的xml字符串,我希望将它们包装成SOAP消息并发送给收件人。我想使用groovy脚本来实现这一点,就像使用curl一样。这意味着我希望避免使用wsdl,而是将现有xml字符串体包装到soap信封中,然后将其发送到收件人的地址和端口。是否有任何方法可以使用wslite或任何其他用于groovy的SOAP api实现此目的?您可以使用HttpBuilder: HTTPBuilder http = new HTTPBuilder( 'http://some.com' ) htt
HttpBuilder
:
HTTPBuilder http = new HTTPBuilder( 'http://some.com' )
http.request( POST ){
uri.path = '/somepath'
requestContentType = URLENC
body = [ your:json, envelope:here ]
headers.Accept = 'application/json'
response.success = { resp, json ->
println json
}
}
或普通的UrlConnection
:
HttpURLConnection connection = new URL( 'http://some.com/somepath' ).openConnection()
connection.requestMethod = 'POST'
connection.doOutput = true
connection.outputStream.withWriter{ it << "{ some:value }" } // here comes your envelop
connection.connect()
String result
connection.content.withReader{ result = new JsonSlurper().parseText( it.readLine() ).someKey }
log.info "got result $result"
HttpURLConnection=newurl('http://some.com/somepath”).openConnection()
connection.requestMethod='POST'
connection.doOutput=true
connection.outputStream.withWriter{it您可以使用HttpBuilder
:
HTTPBuilder http = new HTTPBuilder( 'http://some.com' )
http.request( POST ){
uri.path = '/somepath'
requestContentType = URLENC
body = [ your:json, envelope:here ]
headers.Accept = 'application/json'
response.success = { resp, json ->
println json
}
}
或普通的UrlConnection
:
HttpURLConnection connection = new URL( 'http://some.com/somepath' ).openConnection()
connection.requestMethod = 'POST'
connection.doOutput = true
connection.outputStream.withWriter{ it << "{ some:value }" } // here comes your envelop
connection.connect()
String result
connection.content.withReader{ result = new JsonSlurper().parseText( it.readLine() ).someKey }
log.info "got result $result"
HttpURLConnection=newurl('http://some.com/somepath”).openConnection()
connection.requestMethod='POST'
connection.doOutput=true
connection.outputStream.withWriter{it-Hmm如果我有一个xml代码体而不是json,这是一样的吗?对于客户端部分,这并不重要。如果我有一个xml代码体而不是json,这是一样的吗?对于客户端部分,这并不重要