c12
c12

Reputation: 9827

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?

Upvotes: 7

Views: 15829

Answers (1)

Anders Lindahl
Anders Lindahl

Reputation: 42870

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.

Upvotes: 9

Related Questions