我正在尝试从我的Android应用程序中的PHP webservice获取字符串结果,我使用了ksaop2库,这是我的代码:
env = new SoapSerializationEnvelope(SoapEnvelope.VER11);
env.dotNet = false;
env.xsd = SoapSerializationEnvelope.XSD;
env.enc = SoapSerializationEnvelope.ENC;
request = new SoapObject("customWebService","addProductToCart");
request.addProperty("sessionID", sessionId);
request.addProperty("cartID", cartID);
request.addProperty("productID", productID);
request.addProperty("qty", qty);
request.addProperty("sku", productSKU);
env.setOutputSoapObject(request);
androidHttpTransport = new HttpTransportSE(
"http://mysiteeee.com/WebServiceSOAP/server.php?wsdl/",
60000);
androidHttpTransport.debug = true;
androidHttpTransport.call("", env);
result = env.getResponse();
它返回了这个:
???·???§?? ?¯?²?????? (???§??) ?§???²?§???? ????µ???? ?±?§ ???´?®?µ ?©?????¯.
我在Chrome和Firefox上使用UTF-8编码对其进行了测试,并在浏览器上正确显示结果。
如何从正确编码的Web服务中获取结果并在android上显示?
答案 0 :(得分:0)
尝试以这种方式获得回复:
androidHttpTransport.call(SOAP_ACTION, envelope);
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;
String Test1 = result.getProperty(0).toString();
修改:尝试为请求设置Xml标头标记:
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");