Вопрос

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.

Это было полезно?

Решение

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));
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top