sending binary data via POST on android

情到浓时终转凉″ 提交于 2019-12-21 13:57:33

问题


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:


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



来源:https://stackoverflow.com/questions/3049626/sending-binary-data-via-post-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!