如何使用Android发送KSOAP2请求?

问题描述 投票:0回答:1

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

我在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>

我如何添加那个额外的组,叫做用户,包含我的属性?

java android ksoap2 android-ksoap2
1个回答
0
投票

我这样做了。

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; 

就这样解决了。

© www.soinside.com 2019 - 2024. All rights reserved.