我正在连接到一个 web 服务,即 android 中的 service.asmx。我能够连接到该服务并获得一个响应,但我得到的响应如下。服务器正在向我发送一个有效的 xml,但我无法读取 xml正确。我得到的输出如下
anyType{schema=anyType{element=anyType{complexType=anyType{choice=anyType{element=anyType{complexType=anyType{sequence=anyType{element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; }; }; }; }; }; }; }; diffgram=anyType{}; }
并且用于获得响应的代码如下。envelope.getResponse
会返回一个 xml 格式或者我需要使用其他东西。我已经搜索过,但我仍然不清楚这一点。
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
SoapObject request = new SoapObject(NAMESPACE, MethName);
envelope.setOutputSoapObject(request);
androidHttpTransport.debug=true;
// Property which holds input parameters
PropertyInfo sayHelloPI = new PropertyInfo();
// Set Name
sayHelloPI.setName("UserId");
// Set Value
sayHelloPI.setValue(1);
// Set dataType
sayHelloPI.setType(int.class);
// Add the property to request object
request.addProperty(sayHelloPI);
//Set envelope as dotNet
envelope.dotNet = true;
try {
// Invoke web service
androidHttpTransport.call(SOAP_ACTION, envelope);
// Get the response
SoapObject response = (SoapObject) envelope.getResponse();
System.out.println("response-----------------"+response);