Soap 连接中的流错误

发布于 2024-12-03 03:51:37 字数 1703 浏览 0 评论 0原文

我用java开发android应用程序。并且,该应用程序连接.net肥皂应用程序。没关系,它可以工作(我使用http post方法)。 我的实际问题是 Web 服务返回大量(特别是包含 html --cdata 源代码)数据。 因此,当我向 Web 服务请求(例如 getReports 方法)时,它返回大约 3 - 5 mb 流数据,导致内存不足。因此,我无法解析它。我知道我的连接方法不可能是真的。 如果我犯了错误,如何才能真正执行呢?

提前致谢。

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); 
*/

I develop android application in java. And, this application connects .net soap application. It is ok, it works (i use http post method).
My actual problem is web service returns big and huge (especially contains html --cdata source code) data.
So, when i request (such as, getReports methods) to web service, it returns about 3 - 5 mb stream data, causes outofmemory. Because of this, i couldn't parse it. I know my connection method cannot be true.
How can i implement truely if i make a mistake?

Thanks in advance.

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); 
*/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抚笙 2024-12-10 03:51:37

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;

Ksoap does support headers here is how

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文