Response time in REST client

已回答

The Intellij REST client gives me an answer like 

Response code: 200 (200); Time: 2021ms (2 s 21 ms); Content length: 771481 bytes (771,48 kB)

Can I access the time programatically in client.test()?

I know, that I can measure the time myself, but the client has already measured it.

0

I'm afraid not. The displayed Time: ... value is currently UI/runner metadata rather than a script-accessible property.

The IntelliJ HTTP Client currently does not expose the UI-measured request duration through response or client.test(). The documented response object provides response data such as status, headers, body, and content type, while client.test() only registers assertions.

You will need to measure it yourself. Placing the timestamp in a pre-request script will allow you to include the network request duration:

< {%
  client.global.set("requestStartedAt", Date.now());
%}

GET https://example.com

> {%
  const elapsed = Date.now() - Number(client.global.get("requestStartedAt"));

  client.test("Response time is acceptable", function () {
    client.assert(elapsed < 2000, "Request took too long: " + elapsed + " ms");
  });
%}
0

请先登录再写评论。