Android中调用Web服务获取byte[]

发布于 2024-10-10 01:48:14 字数 738 浏览 0 评论 0原文

我在 Android 上编写了一个应用程序,它调用我编写的 .Net Restful wcf Web 服务。我成功获取了 XML 和 String 结果,但无法调用 Web 服务上返回 byte[] 的方法 - 看起来其编码已收到警报。

我正在使用 org.apache.http.HttpHost 库,并且当前将 byte[] 作为字符串读取(eclipse 中的编码看起来像 unicode);

     InputStream in = response.getEntity().getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        StringBuilder str = new StringBuilder();
        String line = null;
        while((line = reader.readLine()) != null){
            str.append(line);
        }

        in.close();
        String asciiString = str.toString();

基本上我想将 asciiString 中保存的数据转换为位图(WCF 服务输出 PNG 图像的 byte[])

如果有人可以提供指针作为我做错了什么或如何做到这一点(如果可能的话)将是最受欢迎的。

非常感谢

I've writing a application on Android which calls a .Net restful wcf web service I've written. I'm successfully obtaining XML and String results, but cannot call a method on the web service which returns a byte[] - it looks like its encoding is alerted.

I am using the org.apache.http.HttpHost library and an currently reading the byte[] as a string (the encoding in eclipse looks like unicode);

     InputStream in = response.getEntity().getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        StringBuilder str = new StringBuilder();
        String line = null;
        while((line = reader.readLine()) != null){
            str.append(line);
        }

        in.close();
        String asciiString = str.toString();

Basically I want to convert the data held in asciiString to a Bitmap (the WCF service outputs a byte[] of a PNG image)

If anyone can offer pointers as what I am doing wrong or how to do this (if it is possible) it would be most welcome.

Many thanks

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

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

发布评论

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

评论(1

若无相欠,怎会相见 2024-10-17 01:48:14

我相信你应该使用ByteArrayOutputStream。我这里没有安装 IDE,但我认为应该这样做:打开一个 ByteArrayOutputStream,向其中逐字节写入(或者更好,当然以某种方式缓冲)您从 InputStream in 中读取。要获取 byte[],请使用方法 toByteArray()

I believe you should use a ByteArrayOutputStream. I don't have an IDE installed here, but here's how I think it should go: open a ByteArrayOutputStream, to which you write byte by byte (or better, buffering in some way, of course) what you read from your InputStream in. To obtain your byte[] use the method toByteArray().

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