我正在向服务器发送SOAP调用,服务器坚持使用某种Content-Type。我正在尝试设置内容类型,但它似乎没有正确传输。
我收到服务器的回复:
415无法处理消息,因为内容类型为'text / xml; charset = utf-8'不是预期的类型'application / soap + xml; 字符集= UTF-8'
我粗略的代码:
val soapConnectionFactory = SOAPConnectionFactory.newInstance()
val soapConnection = soapConnectionFactory.createConnection()
val url = "https://secure.com"
val messageFactory = MessageFactory.newInstance()
val soapMessage = messageFactory.createMessage()
// (create envelope)
val headers = soapMessage.mimeHeaders
headers.setHeader("Content-Type", "application/soap+xml; charset=utf-8")
soapMessage.saveChanges()
val soapResponse = soapConnection.call(soapMessage, url)
soapConnection.close()
调试通过,内容类型似乎正确设置到soapConnection.call()。有什么想法吗?
答案 0 :(得分:3)
您正在创建默认的MessageFactory:
val messageFactory = MessageFactory.newInstance()
正如doc所说的那样
创建一个新的MessageFactory对象,该对象是默认实现的实例(SOAP 1.1)
SOAP 1.2消息内容类型是" application / soap + xml",而SOAP 1.1是" text / xml" (http://www.w3.org/TR/soap12-part0/#L4697)。
尝试创建一个提供SOAP 1.2作为协议的消息工厂实例
val messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL)