Я пытаюсь добавить XML-декларацию для ex: <?xml version="1.0" encoding="utf-8"?>
начало этого сообщения о мыле. Может ли кто-нибудь помочь мне в том, как это можно сделать?
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")
Этот код должен сделать это.
Вот ссылка на документацию setProperty(String property, Object value)
.
soapMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "UTF-8");
soapMessage.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");