HTTPClient PostMethod for byte[]
Asked Answered
R

1

7

I need to send a byte[] to rest web service end point and I was wondering how to setup the request using HTTPClient's PostMethod, any ideas?

Roseberry answered 27/4, 2011 at 5:39 Comment(0)
S
9

ByteArrayEntity should be what your're looking for:

 [...]
 PostMethod post = new PostMethod(url);
 post.setRequestEntity(new ByteArrayEntity(bytes));
 post.setRequestHeader("Content-type", "application/octet-stream");
 [...]

You will have to set content-type to match what you have in the byte array.

Sympathizer answered 1/5, 2011 at 7:34 Comment(1)
+1 for pointing out you need to set the Content-Type. I totally missed that before and it messed me up.Snoopy

© 2022 - 2024 — McMap. All rights reserved.