0
我有大量從數據庫中選取的xml字符串,我想將它們中的每一個都包裝到SOAP消息中併發送給收件人。我想用一個常規腳本來做到這一點,就像我用捲曲一樣。這意味着我想避免使用wsdl,而是將現有的xml字符串正文封裝到soap信封中,然後將其發送到收件人的地址和端口。有沒有辦法用wslite還是其他的常規SOAP API?Groovy:從信封中創建和發送SOAP請求,而不使用wsdl(如curl)。
我有大量從數據庫中選取的xml字符串,我想將它們中的每一個都包裝到SOAP消息中併發送給收件人。我想用一個常規腳本來做到這一點,就像我用捲曲一樣。這意味着我想避免使用wsdl,而是將現有的xml字符串正文封裝到soap信封中,然後將其發送到收件人的地址和端口。有沒有辦法用wslite還是其他的常規SOAP API?Groovy:從信封中創建和發送SOAP請求,而不使用wsdl(如curl)。
您可以使用該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"
嗯是相同的,如果我的XML代碼,而不是JSON身體? – katolsster
對於客戶端部分它並不重要 – injecteer
謝謝!有效 :) – katolsster