gpt4 book ai didi

java - 创建了错误的 SOAP 请求

转载 作者:行者123 更新时间:2023-11-29 03:12:26 27 4
gpt4 key购买 nike

这是我的代码创建的:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://example.com">
<soapenv:Header/>
<soapenv:Body>
<ws:isUserExists>
<userId>10</userId>
</ws:isUserExists>
</soapenv:Body>
</soapenv:Envelope>

在我的soapenv:Envelope || xmlns:soapenv 来了两次

xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

现在这就是我需要的:SOAP 请求中不存在 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/ " xmlns:ws="http://example.com">
<soapenv:Header/>
<soapenv:Body>
<ws:isUserExists>
<userId>10</userId>
</ws:isUserExists>
</soapenv:Body>
</soapenv:Envelope>

我用来创建请求的 java 代码是:

public static SOAPMessage createIsUserExistsSOAPRequest(User user) throws SOAPException
{
MessageFactory messageFactory =MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
soapMessage.getSOAPHeader().setPrefix("soapenv");
SOAPPart soapPart = soapMessage.getSOAPPart();
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.setPrefix("soapenv");
envelope.addNamespaceDeclaration("ws","http://example.com");

// SOAP Body
SOAPBody soapBody = envelope.getBody();
soapBody.setPrefix("soapenv");
SOAPElement ensureUserExistsElem = soapBody.addChildElement("isUserExists", "ws");
SOAPElement userIdElem = ensureUserExistsElem.addChildElement("userId");
userIdElem.addTextNode(user.userId);
String authorization = new sun.misc.BASE64Encoder().encode(("someid@gmail.com").getBytes());
MimeHeaders hd = soapMessage.getMimeHeaders();
hd.addHeader("Authorization", "Basic " + authorization);
soapMessage.saveChanges();
return soapMessage;
}

请帮忙:我做错了什么?

最佳答案

In my soapenv:Envelope || xmlns:soapenv is coming twice

它没有出现两次。您正在定义 2 个绑定(bind)到同一命名空间的前缀。


xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"

xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"


Please help : what I am doing wrong?

没有。命名空间前缀是 soapenv 还是 SOAP-ENV 还是 polar-bear-ninjas 都没有关系。只要前缀绑定(bind)到命名空间,您就完全限定了该 XML 元素。两个 XML 都是有效的,使用哪个前缀并不重要。

关于java - 创建了错误的 SOAP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28604399/

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