Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jersey Client post binary data application-octet/stream

I would like to perform a post with binary data using Jersey Client.

The equivalent with curl would be:

curl -v --header "Content-Type:application/octet-stream" --data-binary "abc" http://example.com

I could not find how to do it in the official docs: http://jersey.java.net/documentation/latest/user-guide.html#client

Thanks.

like image 650
fernandospr Avatar asked Aug 07 '13 21:08

fernandospr


1 Answers

I think you can invoke a POST request with Entity which encapsulates binary data like this:

Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target("http://example.com/rest");
Response response = webTarget.request(MediaType.TEXT_PLAIN_TYPE)
                .post(Entity.entity("abc", MediaType.APPLICATION_OCTET_STREAM));
like image 156
Septem Avatar answered Oct 19 '22 08:10

Septem