使用Android发送POST / SOAP操作

时间:2013-03-16 12:30:39

标签: android post soap ksoap2

我想了解如何在Android应用程序中发送此XML。我已经读过使用kso​​ap库是一种方法。我试过教程,但似乎没有一个对我有用;甚至样品下载。任何帮助表示赞赏。

POST /nrc/control_0 HTTP/1.1
User-Agent: Panasonic iOS VR-CP UPnP/2.0
Host: 10.0.1.155:55000
Content-Type: text/xml; charset="utf-8"
SOAPACTION: "urn:panasonic-com:service:p00NetworkControl:1#X_SendKey"
Content-Length: 331

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" 
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:X_SendKey xmlns:u="urn:panasonic-com:service:p00NetworkControl:1">
<X_KeyEvent>NRC_MUTE-ONOFF</X_KeyEvent>
</u:X_SendKey>
</s:Body>
</s:Envelope>

1 个答案:

答案 0 :(得分:0)

下面给出了用于进行SOAP调用的代码:

public String callService(String URL, String METHOD_NAME, String NAMESPACE,
        String SOAP_ACTION, String param) {
    String data = "";

    Log.v(webserviceadpater, " \n METHOD_NAME =  ---> " + METHOD_NAME
            + " <--- \n ");

    try {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("xml", param);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);

        envelope.setOutputSoapObject(request);

        HttpTransportSE transportSE = new HttpTransportSE(URL);
        transportSE.debug = true;

        transportSE.call(SOAP_ACTION, envelope);

        SoapObject result = (SoapObject) envelope.bodyIn;

        for (int i = 0; i < result.getPropertyCount(); i++) {
            data = result.getProperty(i).toString();
            Log.v(webserviceadpater, "result = " + data);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return data;
}