我正在尝试发送带有肥皂头的 SOAP 请求,如下所示:
<SOAP-ENV:Header>
<Security xmlns="http://www.xxx.org/xxx/2003/05">
<UsernameToken><Username>yyyy</Username><Password>xxx</Password>
</UsernameToken></Security></SOAP-ENV:Header>
为了做到这一点,我正在使用添加标题元素SoapActionCallback
SoapActionCallback actionCallBack = new SoapActionCallback("https://aaa.com/bbb.asmx") {
public void doWithMessage(WebServiceMessage msg) {
SoapMessage smsg = (SoapMessage) msg;
smsg.setSoapAction("http://www.xxx.org/yyy/2003/05/SessionCreate");
SoapHeaderElement security = smsg.getSoapHeader().addHeaderElement(new QName("http://www.xxx.org/yyy", "Security"));
security.setText("<UsernameToken><Username>yyyy</Username><Password>xxx</Password></UsernameToken>");
}
};
我的问题是肥皂头看起来像这样
<SOAP-ENV:Header><Security xmlns="http://www.xxx.org/yyy/2003/05"><UsernameToken><Username>yyyyy</Username><Password>xxxx</Password></UsernameToken></Security></SOAP-ENV:Header>
结果我的请求失败了:
如何正确添加此消息?