gpt4 book ai didi

java - 将 XML 声明添加到 soap 消息

转载 作者:行者123 更新时间:2023-11-29 05:19:55 25 4
gpt4 key购买 nike

我正在尝试为 ex 添加 XML 声明:<?xml version="1.0" encoding="utf-8"?>到此 SOAP 消息的顶部。谁能帮助我如何做到这一点?

 try {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();

// Send SOAP Message to SOAP Server
String url = "http://ws.cdyne.com/emailverify/Emailvernotestemail.asmx";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);

// Process the SOAP Response
printSOAPResponse(soapResponse);

soapConnection.close();
} catch (Exception e) {
System.err.println("Error occurred while sending SOAP Request to Server");
e.printStackTrace();
}
}

private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPHeader header = soapMessage.getSOAPHeader();

最佳答案

您需要为 SOAP 消息设置一个属性。

soapMessage.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true")

上面的代码应该做到这一点。

这是 linksetProperty(String property, Object value) 文档。

关于java - 将 XML 声明添加到 soap 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25190357/

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