gpt4 book ai didi

ksoap2 - 如何解析 soapfault 的细节?

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

我正在尝试获取此 soap 错误的“详细信息”中的值,但我还没有找到任何方法。

服务器响应:

 <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Many Errors</faultstring>
<detail>
<error_id>2</error_id>
<errors>
<error>
<error_id>1</error_id>
<error_description>Unknown Error</error_description>
</error>
<error>
<error_id>5</error_id>
<error_description>Not Authorized</error_description>
</error>
<error>
<error_id>9</error_id>
<error_description>Password should be at least 6 characters including one letter and one number</error_description>
</error>
</errors>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我需要获取 error_id 及其各自的 error_description。到目前为止,我只能通过以下方式通过 kSOAP 获取 detail:

    if (envelope.bodyIn instanceof SoapObject) {
return envelope.bodyIn.toString();
} else if (envelope.bodyIn instanceof SoapFault) {
SoapFault e = (SoapFault) envelope.bodyIn;
Node details = ((SoapFault) envelope.bodyIn).detail;

}

但是当我尝试“浏览”它时,我还没有设法获得我需要的单个值。

非常感谢任何帮助。我几乎没有找到关于使用 ksoap2 在线处理 soap 故障的信息...

最佳答案

下面的代码处理的更好

Iterator it = soapFaultClientException.getSoapFault().getFaultDetail().getDetailEntries();
while (it.hasNext())
{
Source errSource = it.next().getSource();
@SuppressWarnings("unchecked")
JAXBElement errJaxb = (JAXBElement) springWebServiceTemplate.getUnmarshaller().unmarshal(errSource);
ServerCustomizedError err = errJaxb.getValue();
....
}

关于ksoap2 - 如何解析 soapfault 的细节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15943788/

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