【发布时间】:2021-06-30 13:09:37
【问题描述】:
我正在编写一个脚本来获取 URL 的 TTFB。此 getResponseCode 方法为我提供了 URL 的状态代码。建立连接后,我可以使用什么方法或公式来获取 TTFB?
HttpURLConnection 连接
try {
URL url = new URL('www.xyx.com')
connection = (HttpURLConnection)url.openConnection()
connection.setRequestMethod("GET")
connection.connect()
println(connection.getResponseCode())
}
catch(Exception ex) {
return 0
}
finally {
connection.disconnect()
}
【问题讨论】:
-
你到底不知道什么?如何测量时间?或者如何从流中获取第一个字节?
-
如何使用程序获得 TTFB?我可以在 chrome devtools 中看到 TTFB,但我希望它作为我程序的输出。连接库中有方法吗?
-
标准 java.net 包中没有这样的方法。
-
我可以计算是使用现有方法还是以某种方式从 devtools 中获取?
标签: api groovy katalon time-to-first-byte