Soap连接中的流错误

时间:2011-09-06 08:14:40

标签: java android soap http-post httpurlconnection

我在java中开发android应用程序。并且,此应用程序连接.net soap应用程序。没关系,它有效(我使用http post方法)。 我的实际问题是Web服务返回大而巨大(特别是包含html --cdata源代码)数据。 因此,当我向Web服务请求(例如,getReports方法)时,它返回大约3 - 5 mb的流数据,导致outofmemory。因此,我无法解析它。我知道我的连接方法不可能是真的。 如果我犯了错误,我该怎样才能真实地实施呢?

提前致谢。

String NAMESPACE = "http://tempuri.org/lorem";
String SURL = "http://www.test.com/lorem/test.asmx";
String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
xml += "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://tempuri.org/\">"
        + "<soapenv:Header/><soapenv:Body>"
        + "<web:getReport><web:strLang>strLang</web:strLang></web:getReport>"
        + "</soapenv:Body></soapenv:Envelope>";
URLConnection connection = url.openConnection();
HttpURLConnection httpconn = (HttpURLConnection) connection;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
bout.write(xml.getBytes());
byte[] b = bout.toByteArray();
httpconn.setRequestProperty("SOAPAction", Namespace+ "/" + "getReport");
httpconn.setRequestProperty("Accept-Encoding","gzip,deflate");
httpconn.setRequestProperty("Host","www.test.com");
httpconn.setRequestMethod("POST");
httpconn.setDoInput(true);
httpconn.setDoOutput(true);
httpconn.connect();
OutputStream out = httpconn.getOutputStream();
out.write(b);
InputStreamReader isr = new InputStreamReader(httpconn.getInputStream());
BufferedReader in = new BufferedReader(isr);

String inputLine = "";
StringBuffer parsingData = new StringBuffer();
while (null != (inputLine = in.readLine())) {
    // OutOfMemory Error
    parsingData.append(inputLine);
}

/*
* parsingMethods (parsingData); 
*/

1 个答案:

答案 0 :(得分:0)

Ksoap这里支持标题是如何

Element AuthHeader = new Element();
AuthHeader.setName("Auth");
AuthHeader.setNamespace(namespace);

Element element = new Element();
element.setName("Username");
element.setNamespace(namespace);
element.addChild(Element.TEXT, username);
AuthHeader.addChild(Element.ELEMENT, element);

element = new Element();
element.setName("Password");
element.setNamespace(namespace);
element.addChild(Element.TEXT, password);
AuthHeader.addChild(Element.ELEMENT, element);

headers[0] = AuthHeader;

envelope.headerOut = headers;