我在java中開發android應用程序。而且,這個應用程序連接.net肥皂應用程序。這是可以的,它的工作原理(我使用http post方法)。 我的實際問題是web服務返回大而巨大(尤其是包含html --cdata源代碼)的數據。 因此,當我向Web服務請求(例如,getReports方法)時,它會返回大約3 - 5 MB的流數據,導致內存不足。正因爲如此,我無法解析它。我知道我的連接方法不可能是真的。 如果我犯了一個錯誤,我該如何真正實現?SOAP連接中的流錯誤
在此先感謝。
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);
*/
怎麼有你tryed KSOAP? http://code.google.com/p/ksoap2-android/wiki/HowToUse – PedroAGSantos
是的,我嘗試了很多方法。比如,首先將sdcard保存爲文件,然後讀取 - 解析它。但是,每個設備都沒有sdcard。不是這樣。作爲另一種方法,我創建了一個jsp Web服務器,它向.net服務器發出請求,並將數據作爲解析返回。最後,我很容易理解,事實並非如此。最後,我試圖做ksoap。它不支持我的HTTP標頭.. puff ,,,, –