问题描述
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<ns1:Security xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0">
<ns1:Usernametoken>
<ns1:Username>XXXXX</ns1:Username>
<ns1:Password>XXXXXX</ns1:Password>
</ns1:Usernametoken>
</ns1:Security>
</soapenv:Header>
<soapenv:Body>
<consultarPosicaoCotistaOnOfflineFundoRequest>
<filtro>
<cdCotista>2780008158</cdCotista>
<icSnUltimaPosicao>S</icSnUltimaPosicao>
<ictpSaldo>F</ictpSaldo>
</filtro>
</consultarPosicaoCotistaOnOfflineFundoRequest>
</soapenv:Body>
</soapenv:Envelope>
我正在尝试使用一个网络服务,我需要在我的请求正文中发送上面这个soap对象......但我在下面遇到了这个错误:
Content type 'text/xml;charset=UTF-8' not supported for bodyType=com.sun.xml.messaging.saaj.soap.ver1_1.Message1_1Impl
这就是我要使用的功能:
Mono<String> monoresponse = webClient()
.post()
.header("SOAPAction","")
.header("User-Agent","Apache-HttpClient/4.5.5 (Java/12.0.1)")
.header("Content-Type","text/xml;charset=UTF-8")
.accept(MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML)
.acceptCharset(Charset.forName("UTF-8"))
.bodyValue(soapMessage)
.retrieve()
.bodyToMono(String.class);
monoresponse.block();
我可以通过这种方式发送这个对象吗?!
解决方法
命名空间 https://www.w3.org/2003/05/soap-envelope/
是 SOAP 1.2,其正确的内容类型是 application/soap+xml
。尝试将指定的内容类型更改为此值。内容类型 text/xml
对于 SOAP 1.1 是正确的。