Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTPClient PostMethod for byte[]

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?

like image 572
c12 Avatar asked Apr 27 '11 05:04

c12


1 Answers

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.

like image 151
Anders Lindahl Avatar answered Oct 04 '22 04:10

Anders Lindahl