通过POST在Android上发送二进制数据 [英] sending binary data via POST on android

查看:891
本文介绍了通过POST在Android上发送二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android支持Apache的HTTP客户端(V4)的限定版。 通常,如果我想通过POST使用二进制数据的内容类型=应用程序/八位字节流发送, 我做到以下几点:

Android supports a limited version of apache's http client(v4). typically if I want to send binary data using content type= application/octet-stream via POST, I do the following:


              HttpClient client = getHttpClient();

              HttpPost method=new HttpPost("http://192.168.0.1:8080/xxx");
              System.err.println("send to server "+s);

              if(compression){
                  byte[]compressed =compress(s);
                  RequestEntity entity = new ByteArrayRequestEntity(compressed);  
                  method.setEntity(entity);

              }



              HttpResponse resp=client.execute(method);

不过ByteArrayRequestEntity不支持Android上。我该怎么办?

however ByteArrayRequestEntity is not supported on android. what can I do?

推荐答案

我想你想<一href="http://developer.android.com/reference/org/apache/http/entity/ByteArrayEntity.html"><$c$c>ByteArrayEntity. <一href="http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/methods/ByteArrayRequestEntity.html"><$c$c>ByteArrayRequestEntity从3.X

I think you want ByteArrayEntity. ByteArrayRequestEntity is from 3.x

这篇关于通过POST在Android上发送二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆