gpt4 book ai didi

java - Android:如何创建ksoap2请求?

转载 作者:行者123 更新时间:2023-12-02 07:37:30 25 4
gpt4 key购买 nike

我尝试了解如何在 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/

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