无法在SOAP请求上设置Content-Type [英] Unable to set Content-Type on SOAP Request

查看:1497
本文介绍了无法在SOAP请求上设置Content-Type的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向服务器发送SOAP调用,并且服务器坚持使用某种Content-Type.我正在尝试设置内容类型,但似乎传输不正确.

I'm sending a SOAP call to a server, and the server insists on a certain Content-Type. I'm trying to set the content type but it doesn't seem to be transmitted properly.

我从服务器得到响应:

415无法处理消息,因为内容类型为'text/xml; charset = utf-8'不是预期的类型'application/soap + xml; charset = utf-8'

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().有什么想法吗?

Debugging through, the content type appears to be set properly up to the soapConnection.call(). Any ideas?

推荐答案

您正在创建默认的MessageFactory:

You are creating a default MessageFactory:

val messageFactory = MessageFactory.newInstance()

如文档所述,此方法

创建一个新的MessageFactory对象,该对象是默认实现(SOAP 1.1)的一个实例

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"(

SOAP 1.2 message content type is "application/soap+xml", whereas SOAP 1.1 is "text/xml" (http://www.w3.org/TR/soap12-part0/#L4697).

尝试创建一个提供SOAP 1.2作为协议的消息工厂实例

Try to create a message factory instance providing the SOAP 1.2 as protocol

val messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL)

这篇关于无法在SOAP请求上设置Content-Type的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆