我尝试了解如何在 Android 上使用 ksoap。我已经执行了这个 ksoap 请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:namespace">
<soapenv:Header/>
<soapenv:Body>
<urn:"method name">
<urn:mode>"value"</urn:mode>
</urn:method name>
</soapenv:Body>
</soapenv:Envelope>
通过 AndroidHttpClient 在 HttpPost 的实体部分中。我尝试用 ksoap 做类似的事情:
SoapObject root = new SoapObject(NAMESPACE, "method name");
PropertyInfo pr = new PropertyInfo();
mode.setName("mode");
mode.setValue("value");
root.addProperty(pr);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(root/*request*/);
Log.d(TAG, envelope.toString());
HttpTransportSE transport = new HttpTransportSE(url);
try {
transport.call(NAMESPACE.concat("/").concat("method name"), envelope);
Object obj = (Entity) envelope.getResponse();
,但我有一个异常(exception)
SoapFault - faultcode: 'SOAP-ENV:Server' faultstring: 'Processing Failure' faultactor: 'null' detail: org.kxml2.kdom.Node@44f7cab0
您能否给我举一个这个简单请求的示例,以了解其工作原理?
最佳答案
解决方案:
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.implicitTypes = true;
SoapObject root = new SoapObject(NAMESPACE, "method name");
PropertyInfo mode = new PropertyInfo();
mode.setNamespace(NAMESPACE);
mode.setName("mode");
mode.setValue("value");
mode.setType(String.class);
root.addProperty (mode);
//root.addProperty("mode", "value");
envelope.setOutputSoapObject(root/*request*/);
Log.d(TAG, envelope.toString());
HttpTransportSE transport = new HttpTransportSE(url);
transport.debug = true;
try {
transport.call(NAMESPACE.concat("/").concat("Method of server"), envelope);
Log.d(Qube.TAG, transport.requestDump);
Log.d(Qube.TAG, transport.responseDump);
*如果您想避免 xml 中的类型,顺序很重要
关于java - Android:如何创建ksoap2请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11984868/