可以邮递员或铬显示REST流输出



我有一个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();
}

所有输出线同时显示。我希望看到每 500 毫秒的输出。

我的实现有问题吗?

还是邮递员和Chrome无法显示流媒体输出?

注意:由于技术原因,我仍然使用Postman作为Chrome应用程序。

如果您

正在流式传输,则从 POSTMAN 获取 CURL 请求是不够的。就我而言,需要附加选项

--no-buffer

并且工作正常

cURL 可以

我在使用服务器发送事件时遇到了同样的问题。我已经求助于在Linux机器上使用cURL。我相信Windows会有cURL的替代品。

这篇文章是最近的; https://community.getpostman.com/t/stream-services-listener-how-to-test-in-postman/9714

邮递员目前不支持流媒体API!

但正如他们所说,您可以在 GitHub 上观看该问题以获取更新; https://github.com/postmanlabs/postman-app-support/issues/5040

Postman 刚刚添加了对使用服务器发送事件的支持。请注意,这是从服务器到客户端的单向。

参考: https://blog.postman.com/support-for-server-sent-events/

curl -H '

X_BU_ID:anythingUwant' -H 'Content-Type: multipart/form-data' -v -F 'file=@filePath/abc.csv' http://localhost:35681/stream-test

最新更新