PostMethod post = new PostMethod(http://your.post.com); RequestEntity entity = new ByteArrayRequestEntity(zipbytearray); post.setRequestEntity(entity); httpclient.executeMethod(post);
You might need to encoded the zip byte array using Base64 Hope that help Wilson ----- Original Message ---- From: Matthieu Labour <[email protected]> To: [email protected] Sent: Thursday, June 4, 2009 5:42:26 PM Subject: Sending binary data using HttpPost Hi I apologize if this question is basic I want to send binary data using the http post method of the HttpClient library. Unfortunately the addParameter allows me to set only Strings How can I achieve the following using HttpClient? Thank you for your help! public static byte[] compress(byte[] input) { try { final ByteArrayOutputStream targetStream = new ByteArrayOutputStream(input.length); OutputStream outputStream = new java.util.zip.GZIPOutputStream(targetStream); outputStream.write(input); outputStream.close(); return targetStream.toByteArray(); } catch (IOException e) { throw new RuntimeException("impossible exception?", e); } } ..... HttpClient client = new HttpClient PostMethod httpPost = new PostMethod(" http://localhost:8080/httpclienttest/body"); byte[] dataCompressed = compress(data); hppPost.set("Body", dataCompressed); client.executeMethod(httpPost); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
