【问题标题】:Can Postman or Chrome display REST streaming output?Postman 或 Chrome 可以显示 REST 流输出吗?
【发布时间】:2018-01-02 07:20:38
【问题描述】:

我有一个 REST 服务器,它应该将纯文本输出作为流发送,但是当我使用 Postman 或 Chrome 执行 REST 调用时,我会在进程结束时立即获取整个输出,而不是获取流。

这是我的 REST 服务器,灵感来自 this article

@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 毫秒查看一次输出。

我的实现有问题吗?

或者 Postman 和 Chrome 无法显示流输出?

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

【问题讨论】:

  • 你需要使用 Postman 吗?我认为它不会流式传输,但如果您使用的是 chrome 应用程序,您可以不使用开发工具控制台来测试您需要的内容吗?
  • 我使用 Postman 主要是因为我已经习惯了它,它是我保存我最喜欢的 API 请求的地方。 DevTools doesn't seem 成为 REST 调用的正确工具。我仍然尝试过,但我只能在完全执行后看到输出,就像在 Postman 中一样。
  • 好的,使用开发工具只是一个建议,因为您想查看 数据,而 Postman 不这样做。您可以从 Postman 内部获取 AJAX 代码 sn-p 并在开发工具控制台中使用它或作为 cURL 请求并在终端中查看数据流。我认为邮递员不会满足您的要求。链接的问题是提出标准请求,而不是尝试流式传输数据。

标签: rest stream postman


【解决方案1】:

这篇文章是最近的; 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

【讨论】:

    【解决方案2】:

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

    --no-buffer

    工作正常

    【讨论】:

      【解决方案3】:

      我在使用服务器发送事件时遇到了同样的问题,我在 linux 机器上使用了 cURL。

      我相信 windows 会有 curl 的替代方案。

      【讨论】:

      • 雅真正的卷曲岩石
      • 你能分享 curl 请求吗
      【解决方案4】:

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

      【讨论】:

        猜你喜欢
        • 2017-06-12
        • 2014-07-26
        • 1970-01-01
        • 1970-01-01
        • 2023-03-14
        • 1970-01-01
        • 1970-01-01
        • 2021-06-30
        • 1970-01-01
        相关资源
        最近更新 更多