如何使用 Android 发送 KSOAP2 请求?

How to send a KSOAP2 request using Android?

我已经搜索过类似的问题,但没有找到适合我的答案

我在 android

中从 AsyncTask 调用的函数中包含此代码
SoapObject Request=new SoapObject(NAMESPACE, METHOD_NAME3);

Request.addProperty("mac",emac.getText().toString());
Request.addProperty("name",eusu.getText().toString());
Request.addProperty("status",usuData[0]);
Request.addProperty("cEmpSmarpa",usuData[1]);


SoapSerializationEnvelope envelope =  new 
SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;

envelope.headerOut = new Element[1];
envelope.headerOut[0] = buildAuthHeader();

envelope.setOutputSoapObject(Request);


HttpTransportSE transpor = new HttpTransportSE(URL);
transpor.debug = true;
transpor.call(SOAP_ACTION3,envelope);

resultString=(SoapObject) envelope.getResponse();

然后,我将 XML 发送到我的网络服务

<soapenv:Body>
     <grup:Update>
           <grup:mac>MAC</grup:mac>

           <grup:name>NAME</grup:usuario>

           <grup:status>1</grup:estatus>

           <grup:cEmpSmarpa>0</grup:cEmpresasSmarpa>
     </grup:Update>
</soapenv:Body>

但它不起作用,因为我需要这样发送它

<soapenv:Body>
      <grup:Update>    
         <grup:user>
            <grup:mac>MAC</grup:mac>

            <grup:name>NAME</grup:usuario>

            <grup:status>1</grup:estatus>

            <grup:cEmpSmarpa>0</grup:cEmpresasSmarpa>

         </grup:user>
      </grup:Update>
</soapenv:Body>

如何添加包含我的属性的名为 user 的额外组?

我这样做了:

SoapObject Request=new SoapObject(NAMESPACE, METHOD_NAME3);

SoapObject Soapusuario = new SoapObject(NAMESPACE, "user");

            PropertyInfo pi = new PropertyInfo();
            pi.setNamespace(NAMESPACE);
            pi.setType(PropertyInfo.OBJECT_CLASS);
            pi.setName("user");
            pi.setValue("");
            Soapusuario.addProperty(pi);

但后来我遇到了一些 "i:type=user" 字段错误,所以我添加了

envelope.implicitTypes = true; 

这就解决了。