简体   繁体   English

使用Restlet客户端发送二进制数据

[英]Sending binary data with the Restlet client

I'm trying to send a byte[] (using PUT) with Restlet but I can't find any info on how to do it. 我正在尝试使用Restlet发送一个byte [](使用PUT),但我找不到任何关于如何操作的信息。 My code looks like this: 我的代码看起来像这样:

Request request = new Request(Method.PUT, url);
request.setEntity( WHAT DO I PUT HERE?, MediaType.APPLICATION_OCTET_STREAM);

I had expected to find something along the lines of ByteArrayRepresentation, just like there's a JsonRepresentation and aa StringRepresentation but I couldn't find anything. 我曾期望找到类似于ByteArrayRepresentation的东西,就像有一个JsonRepresentation和一个StringRepresentation但我找不到任何东西。

I believe you want to use an InputRepresentation , like so: 我相信你想使用InputRepresentation ,如下所示:

Representation representation = new InputRepresentation(new ByteArrayInputStream(bytes), MediaType.APPLICATION_OCTET_STREAM);
request.setEntity(representation);

I'm not familiar with restlet, but one way to do it would be to base64 encode the data. 我不熟悉restlet,但其中一种方法是对数据进行base64编码。 Then you could handle it like a regular string. 然后你可以像常规字符串一样处理它。

您可以尝试子类化专门为大型表示设计的WritableRepresentation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM