sending binary data via POST on android

2019-04-09 04:54发布

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

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

1条回答
三岁会撩人
2楼-- · 2019-04-09 05:07

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

查看更多
登录 后发表回答