Col*_*oli 8 rest stream postman
我有一个 REST 服务器,它应该将纯文本输出作为流发送,但是当我使用 Postman 或 Chrome 进行 REST 调用时,我会在过程结束时立即获得整个输出,而不是获得流。
这是我的 REST 服务器,灵感来自这篇文章:
@GET
@Path("/stream-test")
@Produces(MediaType.TEXT_PLAIN)
public Response streamTest(){
StreamingOutput stream = new StreamingOutput() {
@Override
public void write(OutputStream os) throws IOException, WebApplicationException {
Writer writer = new BufferedWriter(new OutputStreamWriter(os));
for (int i=1; i<=10; i++) {
writer.write("output " + i + " \n");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
writer.flush();
}
};
return Response.ok(stream).build();
}
Run Code Online (Sandbox Code Playgroud)
输出行全部同时显示。我希望每 500 毫秒看到一个输出。
我的实现有问题吗?
或者 Postman 和 Chrome 无法显示流输出?
注意:出于技术原因,我仍然使用 Postman 作为 Chrome 应用程序。
我在使用服务器发送事件时遇到了同样的问题。我在 Linux 机器上使用了 cURL。我确信 Windows 会有 cURL 的替代方案。
这篇文章是最近发布的;https://community.getpostman.com/t/stream-services-listener-how-to-test-in-postman/9714
Postman 目前不支持流 api!
但正如他们所说,你可以在 GitHub 上查看该问题以获取更新;https://github.com/postmanlabs/postman-app-support/issues/5040