如何在 Android SOAP Webservices 中将 InputStream 数据转换为字符串

2023-12-20

当我使用来自 Android 的肥皂 Web 服务时,我想在输出字符串中显示结果,如何将该输入流转换为 Sting?

  package com.venkattt.pack;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.SocketException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;

import android.app.Activity;
import android.os.Bundle;

public class SoapWebservicesExampleActivity extends Activity {
    /** Called when the activity is first created. */
      final String NAMESPACE = "urn:sap-com:document:sap:soap:functions:mc-style";
     final String URL = "http://**********:8000/sap/bc/srt/wsdl/srvc_14DAE9C8D79F1EE196F1FC6C6518A345/wsdl11/allinone/ws_policy/document?sap-client=800&sap-user=************&sap-password=*********";
      final String METHOD_NAME = "Z_GET_CUST_GEN";
     final String SOAP_ACTION = "urn:sap-com:document:sap:soap:functions:mc-style/Z_GET_CUST_GEN";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
           SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); // set up
            request.addProperty("Input", "1460");
            request.addProperty("Langu", "d");
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); // put all required data into a soap
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            HttpTransportSE httpTransport = new HttpTransportSE(URL);
            httpTransport.debug = true;

            try {


                 httpTransport.call(SOAP_ACTION, envelope);
                 SoapObject response = (SoapObject)envelope.getResponse();
                 String str = response.getProperty(0).toString();

                 System.out.println("theeeeeeeeeee"+str);



                }
            catch(SocketException ex){
                    ex.printStackTrace();

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


    }

我的最终代码请立即查看并告诉我

我可以在上面的代码中哪里放置该转换?


   String  response = convertStreamToString(instream);

Method

private String convertStreamToString(InputStream is) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line).append('\n');
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return sb.toString();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Android SOAP Webservices 中将 InputStream 数据转换为字符串 的相关文章

随机推荐