gpt4 book ai didi

java - 无法在 SOAP 请求上设置内容类型

转载 作者:行者123 更新时间:2023-11-29 04:23:39 27 4
gpt4 key购买 nike

我正在向服务器发送 SOAP 调用,而服务器坚持使用特定的 Content-Type。我正在尝试设置内容类型,但似乎无法正确传输。

我从服务器收到响应:

415 Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=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()。有什么想法吗?

最佳答案

您正在创建一个默认的 MessageFactory:

val messageFactory = MessageFactory.newInstance()

如文档所述,此方法

Creates a new MessageFactory object that is an instance of the default implementation (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 作为协议(protocol)的消息工厂实例

val messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL)

关于java - 无法在 SOAP 请求上设置内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47600370/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com