gpt4 book ai didi

java - 如何向 SOAP HEader 中的 childNode 添加子节点?

转载 作者:行者123 更新时间:2023-12-01 15:32:24 24 4
gpt4 key购买 nike

我正在尝试在内部创建子节点,它应该如下所示

   <soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-21" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>USER</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PAASS</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">==</wsse:Nonce>
<wsu:Created>2012-02-22T16:27:29.088Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>

具有以下内容

    SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPElement userNameToken = envelope.getHeader().addChildElement("Usernametoken", WSSE_NS_PREFIX, WSSE_NS);
SOAPElement user = userNameToken.addChildElement("UserName", WSSE_NS, WSSE_NS_PREFIX);

尝试这样做时出现以下错误:

    NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.

最佳答案

您似乎混合了参数的顺序(WSSE_NS 与 WSSE_NS_PREFIX)应该是

SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPElement userNameToken = envelope.getHeader().addChildElement("Usernametoken", WSSE_NS_PREFIX, WSSE_NS);
SOAPElement user = userNameToken.addChildElement("UserName", WSSE_NS_PREFIX, WSSE_NS);

关于java - 如何向 SOAP HEader 中的 childNode 添加子节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9419778/

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