Java Restlent对部分请求不返回任何内容

Java Restlent对部分请求不返回任何内容,java,ipad,curl,restlet,Java,Ipad,Curl,Restlet,我使用restlet构建了一个REST-API来提供mp3文件。但文件是同时创建和提供的。更多信息 它工作得很好,但我只在桌面环境中测试了它。当我启动iPad测试API时,它开始播放该文件,但几秒钟后它停止,发送一个新的请求,并从一开始就开始播放该文件 在一些研究人员之后,我发现iPad发送了部分请求,因此期望得到部分响应 因此,我修改了响应头以满足需求 我使用curl测试API: curl -v -r 0-1 http://localhost:12345/api/path/file.mp3

我使用restlet构建了一个REST-API来提供mp3文件。但文件是同时创建和提供的。更多信息

它工作得很好,但我只在桌面环境中测试了它。当我启动iPad测试API时,它开始播放该文件,但几秒钟后它停止,发送一个新的请求,并从一开始就开始播放该文件

在一些研究人员之后,我发现iPad发送了部分请求,因此期望得到部分响应

因此,我修改了响应头以满足需求

我使用curl测试API:

curl -v -r 0-1 http://localhost:12345/api/path/file.mp3
请求头 响应头 错误消息 但是没有从服务器返回的数据。Curl保持与服务器的连接打开,iPad发送一个新请求。 当我关闭服务器时,curl给了我:

transfer closed with 1 bytes remaining to read
Closing connection #0
curl: (18) transfer closed with 1 bytes remaining to read
代码 这是我用来返回数据的代码。如您所见,此方法仅用于测试,应始终返回2个字节。

我不知道该怎么办。我尝试编写自己的InputStream,返回2个字节,但没有成功。 或者输入表示不适合此应用领域


提前谢谢

好的,我解决了这个问题,这是个愚蠢的错误

为了修改响应头,我使用

getResponse().setEntity(new StringRepresentation(" "));
getResponse().getEntity().setSize(19601021);
getResponse().getEntity().setRange(new Range(0, 2));
getResponse().getEntity().setModificationDate(new Date());
getResponse().getEntity().setExpirationDate(new Date());
getResponse().getEntity().setMediaType(MediaType.AUDIO_MPEG);
第一行是旧测试的遗物。如果我只使用实际的InputRepresentation来保存这两个字节,它就可以正常工作了

从中我学到了什么,首先整理代码,然后提问^^

transfer closed with 1 bytes remaining to read
Closing connection #0
curl: (18) transfer closed with 1 bytes remaining to read
private InputRepresentation rangeGetRequest() throws IOException {

    final byte[] bytes = new byte[2];
    bytes[0] = 68;
    bytes[1] = 68;

    final InputRepresentation inputRepresentation = new InputRepresentation(new ByteArrayInputStream(bytes), MediaType.AUDIO_MPEG);

    return inputRepresentation;

}
getResponse().setEntity(new StringRepresentation(" "));
getResponse().getEntity().setSize(19601021);
getResponse().getEntity().setRange(new Range(0, 2));
getResponse().getEntity().setModificationDate(new Date());
getResponse().getEntity().setExpirationDate(new Date());
getResponse().getEntity().setMediaType(MediaType.AUDIO_MPEG);