How to upload binary data using POST

谁都会走 提交于 2019-12-06 15:48:36
ColinD

I think you should use something like Apache HttpClient (or maybe it's in their http-mime module, I haven't used it myself) that can do multipart posts. See this question, for example. Binary data like a JPEG is not character data and really shouldn't be put in a String.

I haven't tried this, but maybe this will work

byte[] data = bos.toByArray();
byte[] boundary = "\r\n--BOUNDARY--\r\n".getBytes();
byte[] fullData = new byte[data.length + boundary.length];
System.arraycopy(data, 0, fullData, 0, data.length);
System.arraycopy(boundary, 0, fullData, data.length, boundary.length);
String entity = new String(fullData); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!