我的肥皂请求看起来像这样
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<Authenticator xmlns="http://www.namespacename.com/services/">
<UserName>string</UserName>
<Password>string</Password>
</Authenticator>
</soap:Header>
<soap:Body>
<ListItems xmlns="http://www.namespacename.com/services/">
<strCode>string</strCode>
</ListItems>
</soap:Body>
</soap:Envelope>
我至少能够使用 ksoap2 成功登录,但我还没有弄清楚正文部分,任何想法如何使用参数 strCode 调用 ListItems,如上所示。
这是当前代码。
String NAMESPACE = "http://www.namespace.com/services/";
String METHOD_NAME = "ListItems";
String SOAP_ACTION = "http://www.namespace.com/services/ListItems";
String URL = "https://www.kupong.se/Services/CouponAPI18.asmx";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
// Enable the below property if consuming .Net service
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.headerOut = new Element[1];
envelope.headerOut[0] = buildAuthHeader();
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope, null);
response = (SoapObject)envelope.getResponse();
}
catch(Exception e)
{
e.printStackTrace();
}
用于为身份验证准备标头值的函数
private Element buildAuthHeader() {
Element h = new Element().createElement(NAMESPACE, "Authenticator");
Element username = new Element().createElement(NAMESPACE, "UserName");
username.addChild(Node.TEXT, username);
h.addChild(Node.ELEMENT, username);
Element pass = new Element().createElement(NAMESPACE, "Password");
pass.addChild(Node.TEXT, "password)
h.addChild(Node.ELEMENT, pass);
return h;
}